Have jquery ajax (php) scripts run one after another instead of at the same time

thanhphong

New Member
Here's the code - this runs as soon as the document is loaded (inside $(document).ready(function(){ ) Is there a way to code this so that the next ajax query will run after the current one is finished? I want to create more ajax calls on the page, but they will not execute until all the queued calls are completed. If each call would run after the other is executed, this will give new ajax calls a chance to get to the front of the next script insead of at the end of all 30. Any advice would be appreciated. \[code\]for (var x=0;x<=30;x++){emailnumber = '<?php echo $storage->countMessages(); ?>'-x;dataString='emailnumber='+emailnumber+'&url=<?php echo $url; ?>&email=<?php echo $email_address; ?>'; $.ajax({ type: "POST", url: "phpdocument.php", data: dataString, success: function(msg){ $('#results').append(msg); } });}\[/code\]Edit: Should I be using the setTimeout function somewhere?
 
Back
Top