开发者

Referencing a custom external javascript file in asp.net mvc 3

Hi I'm trying to pull some javascript on a page off of the page and putting it into an external javascript file for reusability.

Just as a test I'm just t开发者_如何学Pythonrying to display an alert text box but even that's not working.

Here's what I have so far.

Page with the javascript

EDIT: Ignore the type="text/javascript" that wasn't the problem

Referencing a custom external javascript file in asp.net mvc 3

Here's the actual content of the script.js

Referencing a custom external javascript file in asp.net mvc 3

File Structure from the site root

Referencing a custom external javascript file in asp.net mvc 3

Honestly it looks like it should work but whenever I run the page in the browser I'm getting this error.

Referencing a custom external javascript file in asp.net mvc 3

I know that the path is correct, but what am I missing?


The problem was I wasn't clearing my cache, sorry newbie mistake :(


Looks like some simple javascript syntax errors; missing semicolons. You can use JSLint to find those. This should work (Assuming that jQuery is loading before your other two scripts):

Your 'script.js':

var projectApi = function() {};

projectApi.prototype.HelloWorld = function() {
    alert('Hello World');
};

Your page javascript:

$(document).ready(function() {
    var api = new projectApi();
    api.HelloWorld();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜