[英]Why do I receive an Uncaught ReferenceError: $ is not defined
I have a simple show page that has this haml code at the top of the file: 我有一个简单的显示页面,该页面的顶部包含以下haml代码:
:javascript
$(document).ready(function() {
alert('Come on work.....');
});
When I load the page, I receive this error in the console Uncaught ReferenceError: $ is not defined
加载页面时,我在控制台中收到此错误Uncaught ReferenceError: $ is not defined
The problem seems to be similar to this question here ( Uncaught $ error ). 问题似乎与这里的问题类似( Uncaught $ error )。
My application.js looks like this: 我的application.js看起来像这样:
#= require jquery
#= require jquery_ujs
#= require jquery-ui
#= require underscore-min
#= require chosen.jquery.min
#= require app
#= require_tree .
#= require twitter/bootstrap
#= require d3.min
#= require highcharts/highstock
#= require highcharts/highcharts-more
#= require highcharts/solid-gauge
#= require tagcloud
#= require ace-element.min
#= require tipso.min
# Remove the following trigger when TurboLinks are re-enabled
$(document).ready ->
$(document).trigger 'page:change'
I could use some help as to how I can continue trouble shooting all my other javascript files are working fine so I'm not sure what the problem is. 关于如何继续排除所有其他javascript文件的故障,我可以使用一些帮助,所以我不确定是什么问题。
UPDATE 更新 I'm not sure I'm understanding correctly but I've already tried reordering the files in application.js
to this: 我不确定我是否正确理解,但是我已经尝试过将application.js
的文件重新排序为:
#= require_tree . #= require jquery #= require jquery_ujs #= require jquery-ui
And I get a new error saying that JQuery is not defined
. 而且我收到一个新错误,说JQuery is not defined
。 I thought by having this in application.js file the jquery would be present everywhere. 我以为通过在application.js文件中使用它,jquery将随处可见。 What am I missing here. 我在这里想念什么。 Do I need to include the actual files in my show.html.haml
pages? 我是否需要在show.html.haml
页面中包含实际文件?
as @Pointy said the jQuery file needs to be included before your application.js 正如@Pointy所说,需要在您的application.js之前包含jQuery文件。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="application.js"></script>
您将必须在页面中包含jQuery参考
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.