title: Collect AJAX results in order
body: <p>I have an array of values (<code>myarray</code>), that I want to iterate through and run an AJAX request on each iteration.  I've put each ajax request inside another array (<code>requests</code>), so that I can call an <code>alert</code> when all AJAX requests have completed:</p>
  
  <p>Like so:</p>
  
  <pre><code>var requests = [];
  for (i = 0; i &lt; myarray.length; ++i) {
      requests.push($.ajax({
          url: 'anotherurl?=' + myarray[i],
          dataType: "JSONP",
          success: function (data) {
            array_of_results.push(data);
          }
      }));
  }
  $.when.apply($, requests).done(function() {
      alert('complete');
  });
  </code></pre>
  
  <p>All the results are collected in <code>array_of_results</code>.  However due to the AJAX requests taking different lengths of time to complete, this array doesn't have the results in the original order.</p>
  
  <p>Is there any way to order this array?</p>
  
  <p>I hope I've made sense.  I appreciate this is quite convoluted.</p>