I found out that my multiple requests work appropriately when they all succeed, but if one of them fails for whatever reason, my callback is not executed. I dug in the jQuery documentation, that says
In the case where multiple Deferred objects are passed to jQuery.when(), the method returns the Promise from a new "master" Deferred object that tracks the aggregate state of all the Deferreds it has been passed. The method will resolve its master Deferred as soon as all the Deferreds resolve, or reject the master Deferred as soon as one of the Deferreds is rejected
Which means that if I submit n
requests and they all succeed, the master object will trigger a success resolution, and the connected callback (with .then
or .done
) will fire. However, if any of those n
requests fail, the master Promise will be rejected and I will get a failCallback called when the other subpromises are potentially still working. Additionally, I won't have access to those subpromises in the callback unless I play with closures.
What is the correct way of submitting multiple ajax requests in jQuery and have the same behavior regardless if any of them fail?