title: Proper way to loop jQuery ajax and pass arguments
body: <p>I want to solve once for all the problem of looping ajax request and passing 'index' into it (the problem below):</p>
  
  <pre><code>for (var index = 0; index &lt; 4; index++) {
      $.ajax({
          url: 'http://graph.facebook.com/',
          dataType: 'jsonp',
          success: function(json) {
              console.log(json[index]);
          }
      });
  }
  </code></pre>
  
  <p>in this code within every 'success' callback 'index' will be 3. But I want to invoke callback with 0, 1, 2, 3. Many people are placing ajax request within a closure:</p>
  
  <pre><code>for (var index = 0; index &lt; 4; index++) {
      (function(index){$.ajax({
          url: 'http://graph.facebook.com/',
          dataType: 'jsonp',
          success: function(json) {
              console.log(json[index]);
          }
      });
      })(index);
  }
  </code></pre>
  
  <p>what in my opinion is a huge mistake - what if the request won't be there at the time? Than 'json' variable will be 'undefined'.</p>
  
  <p>Does any of You guys have some proper way to solve this issue?</p>