Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using JQuery triggers Uncaught ReferenceError: $ is not defined

I use JQuery in my django project quite often, and it hasn’t been a problem so far. Even in my current project, I use it on multiple pages. But on one page, I get this error in the console:

Uncaught ReferenceError: $ is not defined

This is my JQuery Code:

 $(document).ready(function(){

        console.log("hello")
    
        })

This is what I imported in my base.html:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

Like I said I used JQuery a lot in this project so and it worked fine so far. I also did extend Base.html properly.

What could be the problem?

>Solution :

This error might be caused by these following things:

  1. You’re using the slim version of jQuery, that excludes all Ajax, effects and deprecated code, I am not familiar with this package, so you might want to try the normal package
  2. jQuery is loaded after your script, in your case, you might have extended a block that is contextualized before importing jQuery or maybe some JavaScript is running before the page is loaded, and before jQuery is fully loaded
  3. jQuery is not loaded due to network errors or Cross-origin resource sharing, check the network panel in devtools/firebug aswell as the console for logged errors, to check if it’s loaded, try calling $ in your console

Try comparing how you imported jQuery in the other working templates. Are they extensions of the same base template? Are all of your blocks correctly named? Is your script being run after jQuery is imported?

Hope that can help you!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading