Javascript JQuery:$.get 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1956719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery: $.get is not a function
提问by rplevy
I'm having a problem doing something very basic in jQuery. Can someone tell me what I'm doing wrong exactly?
我在 jQuery 中做一些非常基本的事情时遇到问题。有人可以告诉我我做错了什么吗?
If I run the code below, the function $.get seems to be missing (getJSON and others missing too). But $ itself and other functions do exist, so I know JQuery is loading.
如果我运行下面的代码,函数 $.get 似乎丢失了(getJSON 和其他的也丢失了)。但是 $ 本身和其他函数确实存在,所以我知道 JQuery 正在加载。
google.load("jquery", "1.3.2");
function _validate(form, rules_file) {
$.get('/validation_rules.json',function(data) {
alert("hello")
})
}
Any ideas would be much appreciated.
任何想法将不胜感激。
Thanks, Rob
谢谢,罗布
Edit: here is some additional info:
编辑:这里有一些额外的信息:
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("prototype", "1.6");
google.load("scriptaculous", "1.8");
google.load("jquery", "1.3.2");
</script>
<script>
jQuery.noConflict(); // prevent conflicts with prototype
</script>
<script src="/livepipe/src/livepipe.js"
type="text/javascript"></script>
<script src="/livepipe/src/window.js"
type="text/javascript"></script>
<script src="/livepipe/src/tabs.js"
type="text/javascript"></script>
<script src="/jquery.maskedinput-1.2.2.js"
type="text/javascript"></script>
采纳答案by CMS
The $variable you have is from Prototype-js, because you are using the jQuery.noConflictmethod.
$您拥有的变量来自 Prototype-js,因为您正在使用该jQuery.noConflict方法。
That method will restore the $variable back to whichever library first implemented it.
该方法会将$变量恢复到首先实现它的库。
You should use the jQuery methods on the jQueryglobal object directly, eg.:
您应该jQuery直接在全局对象上使用 jQuery 方法,例如:
jQuery.get(/* .. */);
jQuery.getJSON(/* .. */);
// etc...
Or you can define another shorter variable as alias if you want:
或者,如果需要,您可以将另一个较短的变量定义为别名:
var $j = jQuery.noConflict();
回答by Chris
This will happen, too, if you use the SLIM version of jQuery.
如果您使用 jQuery 的 SLIM 版本,也会发生这种情况。
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
gave me
给我
>jQuery.get
:undefined
>jQuery.get()
:VM7130:1 Uncaught TypeError: jQuery.get is not a function
at <anonymous>:1:8
while loading the same library without the slimoption
在加载没有slim选项的同一个库时
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
works well
效果很好
jQuery.get() :Object {readyState: 1}
jQuery.get() :Object {readyState: 1}
回答by Samuel RIGAUD
Generally speaking, when you are having the $.get is not a functionerror be sure you are not using the slim version of jQuery coming from Bootstrap original imports.
一般来说,当您遇到$.get is not a function错误时,请确保您没有使用来自 Bootstrap 原始导入的精简版 jQuery。
回答by moranjk
You can also wrap your jQuery functions in a closure and pass in jQuery as the "$" sign, eg.:
您还可以将 jQuery 函数包装在一个闭包中,并将 jQuery 作为“$”符号传入,例如:
(function($) {
function _validate(form, rules_file) {
$.get('/validation_rules.json',function(data) {
alert("hello")
})
}
})(jQuery)
回答by Chandra Patni
If you specify jQuery.noConflict(), then $ is no longer available from jQuery. use jQuery.get instead.
如果您指定 jQuery.noConflict(),则 $ 不再可从 jQuery 获得。使用jQuery.get代替。

