$(document).ready(function(){ Uncaught ReferenceError: $ is not defined

后端 未结 8 1483
南笙
南笙 2021-02-06 23:43

Hi I am having a \"Uncaught ReferenceError: $ is not defined\" while using bellow codes

I am currently getting the following error in my log. I have been looking at the

相关标签:
8条回答
  • 2021-02-07 00:21

    It seems you don't import jquery. Those $ functions come with this non standard (but very useful) library.

    Read the tutorial there : http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery It starts with how to import the library.

    0 讨论(0)
  • 2021-02-07 00:26

    No need to use jQuery.noConflict and all

    Try this instead:

    // Replace line no. 87 (guessing from your chrome console) to the following
    
    jQuery(document).ready(function($){
    
    // All your code using $
    
    });
    

    If you still get error at line 87, like Uncaught reference error: jQuery is not defined, then you need to include jQuery file before using it, for which you can check the above answers

    0 讨论(0)
  • 2021-02-07 00:28

    I know this is an old question, and most people have replied with good answers. But for reference and hopefully saving somebody else's time. Check if your function:

    $(document).ready(function(){}
    

    is being called after you have loaded the JQuery library

    0 讨论(0)
  • 2021-02-07 00:32

    If you are sure jQuery is included try replacing $ with jQuery and try again.

    Something like

    jQuery(document).ready(function(){..
    

    Still if you are getting error, you haven't included jQuery.

    0 讨论(0)
  • 2021-02-07 00:34

    Put this code in the <head></head> tags:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
    
    0 讨论(0)
  • 2021-02-07 00:40

    $ is a function provided by the jQuery library, it won't be available unless you have loaded the jQuery library.

    You need to add jQuery (typically with a <script> element which can point at a local copy of the library or one hosted on a CDN). Make sure you are using a current and supported version: Many answers on this question recommend using 1.x or 2.x versions of jQuery which are no longer supported and have known security issues.

    <script src="/path/to/jquery.js"></script>
    

    Make sure you load jQuery before you run any script which depends on it.

    The jQuery homepage will have a link to download the current version of the library (at the time of writing it is 3.5.1 but that may change by the time you read this).

    Further down the page you will find a section on using jQuery with a CDN which links to a number of places that will host the library for you.


    (NB: Some other libraries provide a $ function, and browsers have native $ variables which are only available in the Developer Tools Console, but this question isn't about those).

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