Jquery Ajax call in a loop -
i need make call server , batches of 50 records back. need untill i've had records. can out of this
var stillrecordsavailable = true; var start = 1; while (stillrecordsavailable) { // 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; // } }, error: function(data) { // nothing left stillrecordsavailable = false; } });
try using recursion, call same method until records.
// next batch of records var callserver = function() { $.ajax({ url: '/getrecords.json', data: { data_set_id: dataset.id }, type: 'get', success: function(data) { if (data.records != 0) { callserver();//make ajax call again next records. } // }, error: function(xhr, textstatus, errorthrown) { // nothing left } }); } callserver();
Comments
Post a Comment