title: How do I chain ajax calls properly?
body: <p>using jQuery 3.2.1 I'm chaining calls to $.ajax like this:</p>
  
  <pre><code>function get(i) {
      return $.ajax(...)
        .done(function() { console.log('get done: ' + i) })
        .fail(function() { console.log('get failed: ' + i) })
  }
  
  var p = Promise.resolve();
  for (var i = 0; i &lt; len; i++) {
      p = p.then(get(i));
  }
  
  p.done(function() { console.log('Finished') });
  </code></pre>
  
  <p>and I would expect that the ajax call for i=1 would not execute until the call for i=0 had resolved.  similarly, the final done() should wait for all the calls to be performed in order</p>
  
  <p>in reality I'm seeing 'Finished' before I see anything else and the 'get done' are coming back in random order (the first one finished comes back first is my guess).</p>
  
  <p>I'm used to Bluebird where this would work.  what am I doing wrong?</p>
  
  <p><strong>* Addendum I *</strong></p>
  
  <p>to add to the above, I'm loading javascript files that have dependencies and thus need to be loaded in order.  therefore, the first <em>must</em> complete before the second fetch is initiated, otherwise dependencies will fail</p>