Leonardo
Leonardo

Reputation: 11389

jQuery When().Done() not firing

I'm making some ajax calls and I expect some or all of them to 404. The problem is that when I get a expected 404, the .done() is not executed! What am I doing wrong?

Here is the code:

$.each(data, function (index, item) {
    promises.push(GetReservation(item.UniqueId,
        apiRoot,
        function (data2) {
            //DO stuff
        },
        function (x, y, z) {
            if (x.status == 404) {
                //OK!!! i expected that!
            }
        }));
})
$.when.apply($, promises).done(function () {
    setButtons(box, c)
});

Upvotes: 0

Views: 91

Answers (1)

milagvoniduak
milagvoniduak

Reputation: 3254

Since $.when returns promise, you can call always instead of done. It will invoke callback regardless of the response success.

$.when.apply($, promises).always(function () {
    setButtons(box, c)
});

Upvotes: 1

Related Questions