title: Store AJAX calls into array and call them then
body: <p>I have this snippet. I want to prepare an array of AJAX calls and call them after that. After all AJAXs finish, something will happen, e.g. UI rendering. I tried but the <strong>then()</strong> method is called before the AJAX call. How to fix it?</p>
  
  <pre><code>// In a loop I do this.
  var deferred = getDeleteResultDeferred(resultId, deleteResultSuccessHandler);
  deferreds.push(deferred);
  
  ...
  
  function getDeleteResultDeferred(resultId, deleteResultSuccessHandler) {
      var url = getURI("deleteResult");
      var deferred = $.ajax({
          type : "post",
          url : url,
          data : "resultId=" + resultId,
          success: function(response){
              deleteResultSuccessHandler();
          }
      });
      return deferred;
  }
  
  // Then I call the AJAXs.
  $.when(deferreds).then(function(){
      // UI rendering.
  });
  </code></pre>