[英]jQuery never calls .done() or .always() for ajax call
I'm having this simple get request: 我有一个简单的获取请求:
$.get('ri/i18n/locale')
.done(function() {
console.log(this);
})
.fail(function() {
console.log(this);
})
.always(function(){
console.log(this);
});
Unfortunately none of the handlers are ever called. 不幸的是,没有一个处理程序被调用过。
I cann confirm that calling ri/i18n/locale
in the browser returns a valid JSON string. 我无法确认在浏览器中调用
ri/i18n/locale
返回有效的JSON字符串。 I'm using jQuery 1.11.1 . 我正在使用jQuery 1.11.1。
Any ideas what's wrong? 任何想法有什么问题吗?
Your issue might be what version of jQuery you are using. 您的问题可能是您使用的是哪个版本的jQuery。 Before jQuery 1.5, a
jqXHR
object was not returned with a $.get()
, which is what allows you to use the promise behavior. 在jQuery 1.5之前,没有使用
$.get()
返回jqXHR
对象,这使您可以使用promise行为。 The relevant jQuery documentation . 相关的jQuery文档 。
After all I just missed the asynchronous nature of the ajax call. 毕竟,我只是错过了ajax调用的异步特性。 I had a breakpoint on all
console.log
statements and the statement following the ajax call. 我在所有
console.log
语句和ajax调用之后的语句上都有一个断点。 Since the the statement after the ajax call was hit first I assumed none of the console.log
statements gets called. 由于首先命中了ajax调用后的语句,因此我假设未调用
console.log
语句。
Since I need the result of the ajax call to go on, I have to move all my code into the done()
function. 由于我需要继续进行ajax调用的结果,因此我必须将所有代码移至
done()
函数中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.