title: jQuery Ajax: how to wait until *async* requests success completes before continuing?
body: <p>I'm having a problem making ajax fast <em>and</em> functional. Here's the pseudo/prototype code:</p>
  
  <pre><code>function blah1(arg1){//arg1 is an array, roughly 10 elements
  
  var arr[];
  
  $.each(arg1, function(i){
  //blah code
  
      $.ajax({
          //blah options
          async:   true,
          success: function(data){
              arr[i] = data.someInt;
          }//end success
      });//end ajax
  }//end each
  
  return arr;
  }//end function
  </code></pre>
  
  <p>Basically, I'm sending an ajax and need the returned data for further processing.</p>
  
  <p>If I set async to true, the function immediately returns empty 'arr' array, thus the whole script fails.
  But if I set async to false, then it works, but takes very long.</p>
  
  <p>I have seen this <a href="https://stackoverflow.com/questions/3034874/sequencing-ajax-requests/3035268#3035268">$.ajaxQueue();</a> thing, but frankly I don't understand it at all, and I don't know if it will work.</p>
  
  <p>So the question is, firstly, is there any way I can asynchronously send all the ajax requests at the same time and let function wait and return arr[] after all ajax are done? If not, will the ajaxQueue  work in my case? (rough example please?)</p>