gpt4 book ai didi

javascript - ajaxStop() 不触发

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:36:31 25 4
gpt4 key购买 nike

这是无效的代码:

$(document).ajaxStop(function() {
$(this).unbind("ajaxStop"); //prevent running again when other calls finish

// Display everything
display();
});

这是我的 Ajax 函数:

function getAjax(url, callback) {
jQuery.ajaxPrefilter(function( options ) {
options.global = true;
});

$.ajax({
url: url,
type: "GET",
dataType: "jsonp",
success: callback
});
}

为什么 ajaxStop() 永远不会触发?

最佳答案

您会注意到我正在发出 JSONP 请求。我花了很长时间才找到这个,但可以找到这个问题的答案here .

来自工单:

JSONP requests are not guaranteed to complete (because errors are notcaught). jQuery 1.5 forces the global option to false in that case sothat the internal ajax request counter is guaranteed to get back tozero at one point or another.

If you want all requests to fire the events, no matter what (and at the risk of the same inconsistencies 1.4.4 exhibited), you can use the following prefilter:

jQuery.ajaxPrefilter(function( options ) {
options.global = true;
});

Case in point: http://jsfiddle.net/X4JTx/

关于javascript - ajaxStop() 不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14226776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com