JQuery: $. get 不是一个函数

我在使用 jQuery 做一些非常基本的事情时遇到了问题。有人能告诉我我到底做错了什么吗?

如果我运行下面的代码,函数 $。Get 似乎不见了(getJSON 和其他的也不见了)。但是 $本身和其他函数确实存在,所以我知道 JQuery 正在加载。

google.load("jquery", "1.3.2");


function _validate(form, rules_file) {
$.get('/validation_rules.json',function(data) {
alert("hello")
})
}

任何想法都可以。

谢谢, 罗伯

编辑: 这里有一些额外的信息:

  <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>
79279 次浏览

如果指定了 jQuery.noPulse () ,那么 $就不再可以从 jQuery 获得了。

您拥有的 $变量来自 Prototype-js,因为您使用的是 jQuery.noConflict方法。

该方法将把 $变量恢复到首先实现它的库。

您应该直接在 jQuery全局对象上使用 jQuery 方法,例如:

jQuery.get(/* .. */);
jQuery.getJSON(/* .. */);
// etc...

如果需要,也可以定义另一个较短的变量作为别名:

var $j = jQuery.noConflict();

您还可以将 jQuery 函数封装在一个闭包中,并将 jQuery 作为“ $”符号传递,例如:

(function($) {
function _validate(form, rules_file) {
$.get('/validation_rules.json',function(data) {
alert("hello")
})
}
})(jQuery)

如果您使用 jQuery 的 SLIM 版本,这种情况也会发生。

<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>

给了我

>jQuery.get
:undefined
>jQuery.get()
:VM7130:1 Uncaught TypeError: jQuery.get is not a function
at <anonymous>:1:8

同时加载相同的库而不使用 苗条选项

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

效果不错

JQuery get () 对象{ readyState: 1}

一般来说,当您遇到 $.get is not a function错误时,请确保您没有使用来自 Bootstrap 原始导入的 jQuery 的苗条版本。

对于我 我没有包括 JQuery 脚本。这是解决方案:

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>