JavaScript runtime error: '$' is undefined

前端 未结 6 1320
后悔当初
后悔当初 2020-12-16 18:22

So classic problem, but having a horrible time on finding the actual cause. Typically when I see this error it\'s because the jQuery reference is after code requiring it, or

相关标签:
6条回答
  • 2020-12-16 18:29

    I tried everything listed above and nothing seems to work until I put this string

    <script src="../scripts/jquery-2.2.3.min.js" type="text/javascript"></script>
    

    in the head section of the HTML file. So here's how it looks:

    <!DOCTYPE html>
    <html>
    <head>
    
        <!-- jQuery Reference -->
        <script src="../scripts/jquery-2.2.3.min.js" type="text/javascript"></script>
    
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    
    
        <title>some title</title>
    
    </head>
    <body>
    ...
    

    And the js file is located at a level below in the folder 'scripts'. Finally, the error is gone and what a relief!

    0 讨论(0)
  • 2020-12-16 18:30

    In my case, the problem was that I was rendering my page over https but I was trying to request the JQuery file over http, which is blocked by many browsers for security reasons.

    My fix was to change this...

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    

    ...to this...

    <script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
    

    This causes the browser to download JQuery using the same protocol (http or https) as the page being rendered.

    0 讨论(0)
  • 2020-12-16 18:35

    It's states that JQuery referred URL is not correct

    Try this:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    
    0 讨论(0)
  • 2020-12-16 18:42

    Anover variant, in my case - I was forced to use proxy. So - IE11--> InternetOptions --> Connections-->LANSettings-Proxy Server--> UseProxyServer - should be checked. Also check awailability of jQUery script source, my worked variant in VS2012 - -just like in top example

    0 讨论(0)
  • 2020-12-16 18:42

    I was getting this same error code:

    (Error: 'generateText' is undefined)

    ...on the code

    var bodyText=["The....now."]

    I discovered on my text-editor(Notepad++), when typing many lines of text in the directly above the variable bodyText, if I didn't hit return carriage (enter==>WordWrap is off) just kept typing w/o return carriage and let the editor adjust text it worked?

    Must be in the settings of Notepad++??

    0 讨论(0)
  • 2020-12-16 18:54

    Some of my clients had this problem, because apparently they blocked loading Javascript from 3rd party sites. So now I always use the following code to include jQuery:

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

    This makes sure, that even if my client blocks loading the Javascript file from the CDN domain, the client still downloads the file from my own server, which is not blocked by the browser.

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