Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery.when - Callback for when ALL Deferreds are no longer 'unresolved' (either resolved or rejected)?
    primarykey
    data
    text
    <p>When multiple Deferred objects are passed to <a href="http://api.jquery.com/jQuery.when/" rel="noreferrer">jQuery.when</a>, the method returns the Promise from a new "master" Deferred object that tracks the aggregate state of all the Deferreds it has been passed.</p> <p>The method will either </p> <ol> <li>resolve its master Deferred as soon as ALL the Deferreds resolve, or </li> <li>reject its master Deferred as soon as ONE of the Deferreds is rejected.</li> </ol> <p>If the master Deferred is resolved (ie. ALL the Deferreds resolve), it is passed the resolved values of all the Deferreds that were passed to jQuery.when. For example, when the Deferreds are jQuery.ajax() requests, the arguments will be the jqXHR objects for the requests, in the order they were given in the argument list:</p> <pre><code>$.when( $.getJSON('foo'), $.getJSON('bar') ).done(function(foo, bar) { // foo &amp; bar are jqXHR objects for the requests }); </code></pre> <p>In the multiple Deferreds case where one of the Deferreds is rejected, jQuery.when IMMEDIATELY FIRES the fail callbacks for its master Deferred, even if some of the Deferreds may still be unresolved at that point:</p> <pre><code>$.when( $.getJSON('foo'), $.getJSON('bar') ).fail(function(req) { // req is the jqXHR object for one of the failed requests }); </code></pre> <p>I need to fire a callback when all the Deferreds passed to jQuery.when are no longer 'unresolved' (ie. all are either 'resolved' or 'rejected'). I could send JSON objects with 200 OK codes (instead sending JSON with 404 Not Found error status codes) and determine success/error in the done() method, but I'd prefer keeping my API RESTful. How can I accomplish this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. CO"I need to fire a callback" -- what's the callback, a fail or success? Maybe you could provide an example of the flow of responses and when they should/should not resolve or fail i.e. `page1 --> 200 got page, page2 --> 400 invalid page, page3 --> 200 got page` -- it seems obvious that .fail should be called in this instance, for example.
      singulars
    2. CO@Gary Green - I'm making parallel requests for two JSON resources; if both succeed (return 200 OK), I'm processing both. If one fails (returns 404 Not Found) and one succeeds, I'm showing one kind of error message. If both fail, I'm showing another kind of error message.
      singulars
    3. COFor anyone interested, Alan filed a (poorly named) feature request for this functionality on jQuery's bug tracker: [Ticket #9386 "DEFERREDS FEATURE REQUEST"](http://bugs.jquery.com/ticket/9386). It was closed fairly quickly as "wontfix" with the most important comment being from jaubourg: `-1, Start with a plugin, I'll gladly incorporate this in ajaxHooks (which I'd like to have some deferred helpers too)` -- it would be great to see such a plugin as an answer here!
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload