在promise挂起时延迟执行的回调函数

Callback of deferred to be executed while promise is pending

本文关键字:回调 函数 执行 延迟 promise 挂起 时延      更新时间:2023-09-26

如何配置代码在等待jQuery.Deferred承诺时运行?就像:

$.when(someAJAX).whatever(function() {
    // run this while the AJAX is loading
}).done(function() {
    // run this when it is done
});

我已经检查了文档,并没有发现任何东西,但也许我错过了一些东西(deferred.progress()在这里不起作用)

我认为你想要的比你想要做的要简单得多。相反,您可以这样做:

$.when.apply($, arrayOfPromises).done(function() {
    // code here when ajax call is done
});
// this code will execute right after the ajax call was initiated
// put code here to set state while ajax is loading