title: How to call function after running ajax in for loop
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8726046/multiple-ajax-calls-inside-a-each-function-then-do-something-once-all-of-the">Multiple ajax calls inside a each() function.. then do something once ALL of them are finished?</a>  </p>
  </blockquote>
  
  
  
  <p>How do I execute a function after I run ajax in for loop. Example here I have this ajax running in loop,</p>
  
  <pre><code>for (var countDevice = 0; countDevice&lt;32; countDevice++){
    var dataString="modbus="+(countDevice+1)+"_"+newDate+".xml";
    $.ajax({
      type: "POST",
      url: "CalculateTable",
      data: dataString,
      dataType: "json", 
      //if received a response from the server
      success: function( device, textStatus, jqXHR) {
       //Do something                                 
      }
    });
  }
  </code></pre>
  
  <p>I want to make sure to only run this function below, only after the above for loop is finished.</p>
  
  <pre><code>function drawTable(){
    //Do something
  }
  </code></pre>
  
  <p>Can anyone give any idea on how to make it possible? Thanks for taking the time to read and answer.</p>