简体   繁体   中英

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="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
  <script src="http://bainternet-js-cdn.googlecode.com/svn/trunk/js/jQuery%20BlockUI%20Plugin/2.39/jquery.blockUI.js"></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.

your

<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="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
 <script src="http://bainternet-js-cdn.googlecode.com/svn/trunk/js/jQuery%20BlockUI%20Plugin/2.39/jquery.blockUI.js"></script>

jQuery UI doesn't include the standard jQuery library by default. You'll need to add a <script> tag to include the standard jQuery library before including any plugins that use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM