title: Multiple ajax calls from array and handle callback when completed
body: <p>I have used promises in jQuery slightly before - but I am having trouble applying it to this scenario. I prefer to use the $.when() and $.done() methods to achieve this.</p>
  
  <p>From what I understand I need to build a $.Deferred object which logs the requests and when those requests are finished - fire the callback. In my code below the callback is firing <em>before</em> the ajax requests and not after - maybe I just need some sleep</p>
  
  <p>I know my code is incomplete I have been struggling to apply it with the addition of the for loop.</p>
  
  <p><a href="http://jsfiddle.net/whiteb0x/MBZEu/">http://jsfiddle.net/whiteb0x/MBZEu/</a></p>
  
  <pre><code>var list = ['obj1', 'obj2', 'obj3', 'obj4', 'obj5'];
  var callback = function() {
    alert("done");
  };
  var requests = [];
  
  var ajaxFunction = function(obj, successCallback, errorCallback) {
    for(i = 0; i &lt; list.length; i++) {
      $.ajax({
        url: 'url',
        success: function() {
              requests.push(this);
        }
      });
    }
  };
  $.when($.ajax(), ajaxFunction).then(function(results){callback()});
  </code></pre>