title: Run a function after an ajax looped get completes
body: <p>I'm using ajax to get arrays of points for a googlemap, it works fine apart from I need to call the MarkerClusterer after the final <code>$.get</code> has completed. </p>
  
  <p>If I just place the code after the for loop then it runs before the queued gets have completed and doesn't work correctly.</p>
  
  <p>If I used a callback on the <code>$.get</code> then it will run on each loop which is not what I want either</p>
  
  <p><strong>The code</strong></p>
  
  <pre><code>for (i = 1; i &lt;= &lt;?=$pages;?&gt;; i++) {
  
      points = [];
  
      $.get("/mappoints/" + i + "/true", function(data) {
  
          $.each(data.json_array, function(index, value){
  
              //do things with data
          });
      }, "json");         
  }
  
  //run this code after the queued `$.get`s have **all** completed
  console.log("done");
  var markerCluster = new MarkerClusterer(map, markers);
  </code></pre>
  
  <p>I've tried the following within the <code>for</code> but that didn't even run, not too sure why?</p>
  
  <pre><code>if(i == &lt;?=$pages;?&gt;){
      var markerCluster = new MarkerClusterer(map, markers);
      console.log("done");
  }
  </code></pre>