TypeError: $.ajax(...) 不是函数? [英] TypeError: $.ajax(...) is not a function?
问题描述
我正在创建一个简单的 AJAX 请求,它从数据库中返回一些数据.这是我的功能如下:
I'm creating a simple AJAX request which returns some data from a database. Here's my function below:
function AJAXrequest(url, postedData, callback) {
$.ajax({
type: 'POST',
url: url,
data: postedData,
dataType: 'json',
success: callback
});
}
这里是我调用它的地方,提供所需的参数:
Here's where I call it, providing the required parameters:
AJAXrequest('voting.ajax.php', imageData, function(data) {
// function body
});
然而,回调没有运行,而是在控制台中出现错误:
Yet, the callback does not run, and instead I get an error in the console:
TypeError: $.ajax(...) is not a function.
为什么?在成功事件触发 $.ajax 内的匿名函数之前,我已经完成了 AJAX 请求,但现在我正在尝试运行一个单独命名的函数.我该怎么做?
Why? I've done AJAX requests before where the success event triggers an anonymous function inside of $.ajax, but now I'm trying to run a separately-named function. How do I go about this?
推荐答案
这里的答案都没有帮助我.问题是:我使用的是 jQuery 的精简版,其中删除了一些东西,ajax 就是其中之一.
Neither of the answers here helped me. The problem was: I was using the slim build of jQuery, which had some things removed, ajax being one of them.
解决方案:只需在此处下载常规(压缩或未压缩)版本的 jQuery 并将其包含在您的项目中.
The solution: Just download the regular (compressed or not) version of jQuery here and include it in your project.
这篇关于TypeError: $.ajax(...) 不是函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!