请定期到来的比赛条件下空空的回来 [英] Request periodically coming back empty under race conditions

查看:76
本文介绍了请定期到来的比赛条件下空空的回来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么可能是下面的可能原因?

What might be the possible cause of the following?

我使用的是自动完成的脚本与下列code:

I am using an autocomplete script with the following code:

if (that.currentAjaxRequest !== null) {
    that.currentAjaxRequest.abort();
}

that.currentAjaxRequest = $.get(query_string,
    function(data) {
        that.doStuff(data);
    }
);

剧本是节流。因此,有大约300 NBSP延迟;每次键击后毫秒之前的请求被发送

The script is throttled. So there is a delay of about 300 ms after every keystroke before a request gets sent.

这在我的测试环境工作得很好。不过,我运行到环境中生活的情况下,定期,如果请求得到发送接近海誓山盟(约以往任何时候都300 NBSP; MS),每过一段时间中的最新要求回来空。也就是说,数据将是未定义。为什么会这样呢?

This works just fine in my test environment. However, I'm running into a situation in the live environment where, periodically, if requests get sent close to eachother (about ever 300 ms), every once in awhile the latest request comes back empty. That is to say, data will be "undefined". Why might this be?

推荐答案

这似乎是一个 jQuery的错误 1.4中介绍:当手动中止Ajax调用,jQuery将调用函数的成功与一个空字符串,而不是误差函数

This seems to be a jQuery bug introduced in 1.4: When manually aborting an ajax call, jQuery will call the success function with an empty string instead of the error function.

您可以解决此通过检查 xhr.status 在回调:

You can work around this by checking xhr.status in your callback:

function(data, textStatus, xhr) {
    if (xhr.status) {
        //a successful call
    }
    else {
        //an aborted call
    }
}

这篇关于请定期到来的比赛条件下空空的回来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆