Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you use <code>$.when</code> (I know, funny sentence ;)), then the values with which the promises are resolved are passed as arguments to the callback functions. I.e. in your <code>done</code> callback, the first argument refers to the resolved value of <code>deferred1</code> and the second argument to <code>deferred2</code> (whatever that is).</p> <p>Now, when an Ajax success callback is called, it gets passed three arguments:</p> <ul> <li>the response</li> <li>the status text</li> <li>the <code>jqXHR</code> object</li> </ul> <p>You are only interested in the first.</p> <p>So with this, your setup should be:</p> <pre><code>var promise1 = $.get(url); var promise2 = $('#content').fadeTo(100, 0, 'linear').promise(); $.when(promise1, promise2).done(function(ajax_success) { $('#content').html(ajax_success[0]).fadeTo(400, 1, 'linear'); }); </code></pre> <p>Also have a look at the <a href="http://api.jquery.com/jQuery.when/" rel="nofollow noreferrer"><code>$.when</code> documentation</a>.</p> <hr> <blockquote> <p>Do I need <code>promise</code>?</p> </blockquote> <p>No. It looks like <code>$.when</code> calls <code>.promise</code> internally when you pass a jQuery collection. But in other cases you would have to, so it makes sense to do this here as well, for consistency (thanks <a href="https://stackoverflow.com/users/6782/alnitak">Alnitak</a>).</p> <blockquote> <p>And should i ... ? Should I ...? What would be ...?</p> </blockquote> <p>There is no standard solution for this kind of problems. Promises are incredibly flexible and there are so many ways to use. I <em>think</em> they are not around long enough in JavaScript for standard patterns to emerge. Find/create something that makes sense to you and be consistent within your application.</p> <p>The only thing I would recommend to do if you have multiple promises is put them in an array: <a href="https://stackoverflow.com/q/8011652/218196">jQuery $.when() with variable arguments</a>.</p>
    singulars
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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