title: Trying to use jquery $.when() & .done() with 2x $.ajax calls but the done() is getting called immediately
body: <p>I'm trying to make 2x Ajax calls at the same time (async) with jQuery, like the following:</p>
  
  <pre><code>function displayAccount() {
      $.when(doGet("accounts/1", null),
             doGet("orders/1", null))
          .done(displayAccountSuccess);
  }
  
  function displayAccountSuccess(accountJson, ordersJson) {
    console.Info(accountJson);
    console.Info(ordersJson);
  }
  </code></pre>
  
  <p>When I do this, the <code>displayAccountSuccess</code> is called BEFORE the 2x <code>doGet</code>'s are called/handled. Of course, the values of the two method arguments are <code>undefined</code>.</p>
  
  <p>So obviously my <code>doGet</code> isn't returning a promise :(</p>
  
  <p>For that method... </p>
  
  <pre><code>function doGet(endpoint, queryString)
  {
      var url = ApiWebsite + "/" + endpoint;
      if (queryString)
      {
          url += "?" + queryString;
      } 
  
      var authorizationHeader = isAuthenticated()
          ? "bearer " + localStorage.getItem(LocalStorageJwt)
          : "";
  
      $.ajax({
          url: url,
          headers: {
              authorization: authorizationHeader
            }
      })
      .done(function(json)
      {
           return json; 
      })
      .fail(function(data1, data2){ 
          displayError("fail");
      }).promise();
  }
  </code></pre>
  
  <p>Ok - now this is what is interesting :) the <code>ajajx.done</code> method DOES have the correct json response in there! So I -thought- I was returning that json data back to the caller.</p>
  
  <p>Now, if i change the code from:</p>
  
  <pre><code>$.ajax(....
  </code></pre>
  
  <p>to </p>
  
  <pre><code>return $.ajax(....
  </code></pre>
  
  <p>the <code>when.done(..)</code> function <strong>is</strong> delayed and only called <em>after</em> the 2x ajax calls are completed! Yay!  ..but ... the VALUE of this data is an array of 3 items .. the <code>data, successTest, jqXHR</code> :( Sure, I can just get the json value from array slot 0 (<code>accountJson[0]</code>) but this means I'm not understanding something pretty basic here :(</p>
  
  <p>I'm hoping that my <code>done()</code> method will accept 2x json objects only, not the full SUCCESS (or failure) array.</p>
  
  <p>I hope this makes sense :blush:</p>