title: Cannot break recursion with $.Deffered() object and $.then()
body: <p>I have to search through word index tables with potentially hundreds of thousands rows. I can restrict my search by passing a list of documents to the search. Request to search for words in many documents return very slowly. So...to improve the UX we're chunking the request into several groups of documents. So, if a user asks to search 90 documents, and the chunk size is 10 documents per query, then we send out 90 / 10 = 9 independent $.ajax() calls. We want the results to come in the order they were sent.</p>
  
  <h2>We implement this recursion:</h2>
  
  <pre><code>var SearchFunction = function () {
     $.ajax(/* ... */);
     }
  
  var RecursiveSearch = function () {
     var deferred = $.Deferred();
     if (arrTransSearch.length &gt; 0) {
        deferred = SearchDocuments(arrTransSearch.shift());
     }
     else {
        deferred.reject();
     }
  
     return deferred.promise().then(RecursiveSearch);
  }
  
  if (arrTransSearch.length &gt; 1) {
     RecursiveSearch().fail(SomeFunction);
  }
  
  var SomeFunction = function () {
     alert("Failed. Yes!");
  }
  </code></pre>
  
  <p>When I debug the code, it <em>appears</em> that  <code>deferred.reject()</code> does not change the state of <code>deferred.promise()</code>. That is, when the next line </p>
  
  <pre><code>return deferred.promise().then(RecursiveSearch)
  </code></pre>
  
  <p>is executed, it just loops back into the recursive function, instead of exiting the recursion and falling into     </p>
  
  <pre><code>RecursiveSearch().fail(SomeFunction);
  </code></pre>
  
  <h2>Important Note:</h2>
  
  <p>I'm using <strong>jQuery-1.7.1</strong>. I ran analogous recursion in <a href="http://jsfiddle.net/Seabiscuit/UXqrj/11/" rel="nofollow noreferrer">JSFiddle</a> (Thank you <a href="https://stackoverflow.com/a/21660400/2112866">Beeetroot-Beetroot</a>) and it failed on <strong>jQuery-1.7.2</strong> while on <strong>jQuery-2.1.0</strong> it ran without a problem.</p>
  
  <p>Any idea on how to get the recursion to work in <strong>jQuery-1.7.1</strong>?</p>