简体   繁体   English

具有单个失败回调的多个Ajax调用

[英]Multiple ajax calls with single fail callback

I have two arrays with deferreds, to see if outer when or inner when failed I need to use double fail callback aplaying. 我有两个阵列,deferreds,看外when或内部when失败,我需要使用双重fail回调aplaying。 Is there any way to populate error from inner when and use single fail ? 有什么办法来填充从内部错误when以及使用单fail

 $.when.apply(null, array1).done(function () {
            $.when.apply(null, array2).done(function () {
                alert("all done, yupi");
            }).fail(failCallback);
        }).fail(failCallback);

This is how it would be done using ES6 promises 这就是使用ES6 Promise完成的方式

Promise.all(array1).then(function() {
    return Promise.all(array2);
}.then(function () {
    alert("all done, yupi");
}.catch(failCallback);

So, I assume jQuery would be done like 因此,我认为jQuery会像

$.when.apply(null, array1).then(function () {
    return $.when.apply(null, array2);
}.then(function () {
    alert("all done, yupi");
}).fail(failCallback);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM