PDA

View Full Version : How to get to know that all the ajax processes has completed?



renganathan
10 May 2012, 10:43 PM
Hi All,

i am firing multiple ajax calls in parallel . Each ajax calls start same time but its take different time to finish.

once all the ajax calls has completed i need to call another function.

please help me to fix this problem.





for(i=0; i<selected_count; i++)
{
var termIPADDR = uniqueIPstore.data.items[i].data.ip_address;
var URLProfile = '../cgi-bin/scan_device.pl';
Ext.Ajax.request(
{
waitMsg : 'Please wait...',
url : URLProfile,
async : true,
params :
{
ip_address : termIPADDR
},
success : function(response)
{
Ext.getBody().unmask();
},
failure : function(response)
{
Ext.getBody().unmask();
Ext.MessageBox.alert('error',termIPADDR+ 'is failed');
}
});
}

// after all process completed
// call another function

redraid
11 May 2012, 12:42 AM
var requestCount = 5,
requestComplete = 0,
onAjaxComplete = function () {
requestComplete++;

if (requestComplete >= requestCount) {
// all ajax requests complete
alert('Complete');
}
};

for (var i=0; i<requestCount; i++) {
Ext.Ajax.request({
// @todo: ajax request config
success: function () {onAjaxComplete();},
failure: function () {onAjaxComplete();}
});
}

renganathan
11 May 2012, 1:13 AM
Thanks for your solution.





var requestCount = 5,
requestComplete = 0,
onAjaxComplete = function () {
requestComplete++;

if (requestComplete >= requestCount) {
// all ajax requests complete
alert('Complete');
}
};

for (var i=0; i<requestCount; i++) {
Ext.Ajax.request({
// @todo: ajax request config
success: function () {onAjaxComplete();},
failure: function () {onAjaxComplete();}
});
}