如何修复jQuery库中的"jQuery未定义"错误?

问题描述:

修复此问题:确保在加载任何脚本之前先<%= javascript_include_tag "application" %>,以便首先加载jquery.

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

这似乎很奇怪.加载页面时,我收到2个js错误(在Chrome中):

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>

因此,第一个包含的内容是与自身相关的javascript错误?这似乎不太可能.这看起来像是一个错误定向错误的情况(实际错误在其他地方).我该怎么做才能解决此问题?页面上的JS错误看起来有点不专业(至少对其他开发人员而言).前几天我没有收到这个错误-甚至还原了代码以确保.

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.

您的

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

需要在jQuery ui<之前调用脚本>标签.

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

应显示如下:

 <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>