Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. JQuery Wait for Ajax Response
  2. for (i=1;i<=pages;i++) {
  3.         $('#procout').append(Processing Page#"+i+"<br />");
  4.         $.ajax({
  5.             url: 'processor.php',
  6.             data: {storen: perpage, pagen : i},
  7.             success: function(data) {
  8.                 $('#procout').append(data+"<br />");
  9.  
  10.             }
  11.         });
  12.     }
  13.        
  14. function runRequest(num){
  15.     if (num > pages) return; //since your original was looping while i <= pages
  16.  
  17.     $('#procout').append("Processing Page#" + num + "<br />");
  18.     $.ajax({
  19.        url: 'processor.php',
  20.        data: {storen: perpage, pagen : num},
  21.        success: function(data) {
  22.            $('#procout').append(data + "<br />");
  23.  
  24.            runRequest(num + 1);
  25.        }
  26.     });
  27. }
  28.        
  29. runRequest(0);