Jquery Ajax调用循环

时间:2015-08-25 06:04:09

标签: jquery ajax

我需要调用服务器并获取50个记录的批次。我需要这样做,直到我有所有记录。有人可以帮忙吗

var stillRecordsAvailable = true;
var start = 1;
   while (stillRecordsAvailable) {
   // get the next batch of records
   $.ajax({
      url: '/getData?start='+start+'&recordLimit=50',
      type: 'GET',
      success: function(data) {
        if(data.records == 0){
           stillRecordsAvailable = false;
        }
        else{
          start += 50;
        // do something
        }    
      },
      error: function(data) {
       // nothing left to do
      stillRecordsAvailable = false;
    }
  });

0 个答案:

没有答案