I'd like two make two AJAX requests for data. One or both of the requests may fail. In that case I still would like to interact with the data from both requests (or the successful request).
If I do something like:
$.when($.get("page1"), $.get("page2")).then(function(a1, a2) {
})
The then
function will only get called if both requests succeed, so if one fails, I can't get any of the data from the successful request. If I use a failCallback for then, or use the always method, like this:
$.when($.get("page1"), $.get("page2")).then(function(a1, a2) {
console.log("this is only called if both succeed.");
}, function(a1, a2, a3) {
console.log("this is only called with a then() failure");
}).always(function(a1, a2, a3) {
console.log("this will fire when always() does.");
});
The failCallback and always callback only report data on the failed request, so I can't get data out about the successful request. Similarly, using the done() deferred doesn't call if one of the requests fails. So there's a situation where if one request 404s, I can't get any data from the successful function.
I suppose I could decouple the deferreds, so they are not both in the when loop. However then I run into issues with ensuring that both finish before proceeding.