Skip to content Skip to sidebar Skip to footer

Combining Deferred Responses

Is it possible, when using jQuery Deferred's $.when to combine the responses into an array? var promise = $.when( ajaxRequest1, ajaxRequest2 ); promise.done(callback); Th

Solution 1:

The problem is that jQuery resolves its ajax promises with 3 arguments, which then become an array of values when you are using $.when on multiple promises. To get only the data (the first argument of each ajax callback), use

var promise = $.when(
    ajaxRequest1,
    ajaxRequest2
).then(function(resp1, resp2) {
    return [resp1[0], resp2[0]];
});

Post a Comment for "Combining Deferred Responses"