'JQuery' is undefined

前端 未结 19 1410
生来不讨喜
生来不讨喜 2020-12-28 15:21

I am working on a ASP.net project created with local file system settings. I am using MVC and Jquery. Jquery is working fine when I run the application in debug mode i.e. in

相关标签:
19条回答
  • 2020-12-28 16:15

    If there's no errors in your javascript (eg: missing brackets), then it's either not including the jQuery file, or you're trying to run some code which relies on jQuery before that file has loaded.

    0 讨论(0)
  • 2020-12-28 16:17

    Correct! I have chased this down for days now, when you are using a new MVC project from scratch in VS, it has its own references to JQuery in the Layout.cshtml page. If you are attempting to reference JQuery within a page, it will get overwritten by the reference in the Layout.cshtml page. Comment the code in the masterpage (Layout.cshtml), and it will use your page references.

    0 讨论(0)
  • 2020-12-28 16:19

    0 I do not know whether you guys found the solution to your problem or not. I was facing the same problem and going nuts to figure out why do I get "jQuery is undefined" error on the plugins i use. I tried all the solutions i get from the internet but no luck at all.

    But, suddenly something splash on my mind that may be the script files should be in order. So, I moved the jquery referece to first position and everything start working like charm.

    Remember guys, if you're using any plugins with jquery, make sure you use the folloing order of setting reference to those fiels.

    1. reference to the jquery library
    2. reference to the other subsequent plug-in (dependant) libraries and so on...

    e.g.:

    1. "script src="js/jquery-1.3.2.min.js" type="text/javascript"...
    2. "script src="js/jqDnR.min.js" type="text/javascript"...
    3. "script src="js/jquery.jqpopup.min.js" type="text/javascript"...
    4. "script src="js/jquery.bgiframe.min.js" type="text/javascript"...

    Always make sure you must put the jquery reference to first and then the subsequent libraries.

    Hope, this solves your problem especially when you use with MasterPages. Its very strange that it works no matter what order you use when you don't use MasterPages but when you do, then it somehow requres the proper order.

    Good luck and happy coding,

    Vincent D'Souza

    0 讨论(0)
  • 2020-12-28 16:19

    To elaborate on the "text/javascript" answer, "application/javascript" will work in firefox and load jQuery just fine. It won't, however, load the file in IE. Use "text/javascript":

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
    
    0 讨论(0)
  • 2020-12-28 16:20

    To add my problem/solution to this long list...

    I was using Windows 2003 to test the site in IE7. The site came up fine but jQuery didn't run at all. So I went straight to the http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js and found that ajax.googleapis.com was not on the list of safe sites. After adding *.googleapis.com everything worked fine. Silly oversight, but maybe this will help someone else in a similar situation.

    0 讨论(0)
  • 2020-12-28 16:22

    The path is wrong. Double check it.

    0 讨论(0)
提交回复
热议问题