简体   繁体   English

为什么会收到未捕获的ReferenceError:未定义$

[英]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.

相关问题 为什么会出现Uncaught ReferenceError:未定义scrollToM? - Why do I get Uncaught ReferenceError: scrollToM is not defined? 为什么会收到“未捕获的ReferenceError:未定义$(匿名函数)” - Why do I get an “Uncaught ReferenceError: $ is not defined (anonymous function)” 为什么我会收到此错误:“未捕获的 ReferenceError:未定义 value1”? - Why do I get this error: “Uncaught ReferenceError: value1 is not defined”? 为什么收到“未捕获的ReferenceError:未定义要求”? - Why I get “Uncaught ReferenceError: require is not defined”? 未捕获的ReferenceError:我没有定义 - Uncaught ReferenceError: i is not defined Javascript:未捕获的 ReferenceError:我未定义 - Javascript: Uncaught ReferenceError: i is not defined 为什么会出现“ Uncaught ReferenceError:未定义userId”错误? - Why am I getting “Uncaught ReferenceError: userId is not defined” error? 为什么我收到 Uncaught ReferenceError: myData is not defined 的错误? - Why is that I got an error of Uncaught ReferenceError: myData is not defined? 我为什么会收到“ Uncaught ReferenceError:未定义反应” - Why am I getting “Uncaught ReferenceError: React not defined” 为什么我得到:Uncaught ReferenceError: response is not defined - why am i getting: Uncaught ReferenceError: response is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM