Javascript – how to fix ‘jQuery is not defined’ error in jquery library


Rails fix: make sure <%= javascript_include_tag "application" %> is before any script loading so that jquery gets loaded first.

This seems really odd. When I load my page I get 2 js errors (in Chrome):

jquery-ui.min.js:17  Uncaught ReferenceError: jQuery is not defined
jquery.blockUI.js:499  Uncaught ReferenceError: jQuery is not defined

Ok, that seems… odd. So I look at my script includes. My first two script includes on my page:

 <script src=""></script>
  <script src=""></script>

So the first include is getting a javascript error related to itself? That seems unlikely. This looks like a case of a misdirection error (the real error is somewhere else). What can I do to fix this? JS errors on pages look a little unprofessional (at least to other devs). I wasn't getting this error the other day — even reverted the code to make sure.

Best Solution


<script type="text/javascript" src="jquery.js"></script> 

needs to be called before jquery ui < script > tags.

Should appear like this:

 <script type="text/javascript" src="jquery.js"></script> <-- put me here -->
 <script src=""></script>
 <script src=""></script>