kosnkov
kosnkov

Reputation: 5911

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. Is there any way to populate error from inner when and use single fail?

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

Upvotes: 0

Views: 47

Answers (1)

Jaromanda X
Jaromanda X

Reputation: 1

This is how it would be done using ES6 promises

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

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

Upvotes: 3

Related Questions