开发者

"jQuery is not defined" error comes up sometimes

In my Asp.Net MVC2 app, the JS error 'jQuery is not defined' comes up 开发者_Python百科sometimes (1 out of 20 times).

Because of this unsymmetrical trend, I'm unable to point out the problem.

Any suggestions?

Thanks.


if you are useing a CDN use this code:

   <script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
   <script>window.jQuery || document.write('<script src="js/libs/jquery-1.5.1.min.js">\x3C/script>')</script>

it uses the google CDN but provides a fallback. And it has a protocol relative URL

see: theHTML5Boilerplate


Use Firefox with Firebug installed. When you get the error use the DOM inspector to make sure you're loading jQuery before any plugins, and that jQuery it not 404'ing (use the net panel.)

Note that you can't view source at this point because when you view source you're making an additional HTTP request to the server.

You can also download a proxy like Charles (free to try) and enable logging. Refresh your page 20 times, stopping when you see the JS error. Check Charles and view the source of the HTML document. You can also compare the markup this time to the markup of a previous successful request. The problem can either be:

  1. You're loading a jQuery plugin before you are loading jQuery.
  2. You're not loading jQuery (if so, check the code that usually outputs this line.)
  3. The place you're loading jQuery from occasionally isn't working.
  4. Not likely, but you're overriding the jQuery variable.

Whatever the case, the above steps should help find the problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜