12

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.

7
  • 4
    Where's the script tag for jQuery itself? Commented Feb 13, 2012 at 19:28
  • 3
    You must include jQuery before using jQuery UI. Commented Feb 13, 2012 at 19:28
  • 2
    jQuery !== jQuery UI, you have to include the "base" jQuery as well. Commented Feb 13, 2012 at 19:28
  • @JamesMcLaughlin hmm, checking, I haven't touched this code for a while. Commented Feb 13, 2012 at 19:29
  • @All: this looks like a rails issue, I had '//= require jquery' in my application.js but it seems to not be loading. Commented Feb 13, 2012 at 19:35

2 Answers 2

23

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Anyone having this issue in Rails should be sure and see my edit to the question that has a Rails-specific fix.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.