I send several ajax request at a time. But as you know that the result arrival time isn't related with the time you send request. Now, this make a problem to me.
Here's what I face now.
When I click the TAB button made with HTMLElement, it sends ajax call.
If I click the tab just after clicking other tab. two request goes together and I can't know which one could response to me first. but unfortunately last one sometime arrive earlier than the first ajax request.
then, it occur my html markup messy, so my question is is there any way to make ajax call arrive in regular sequence.
initialize : function() { //<!-- this function call AJAX request
this.getActivatedDeviceList();
this.getDeActivatedDeviceList();
this.getLostOrStolenDeviceList();
this.getWaitingDeviceList();
},
getActivatedDeviceList : function() {
var url = "/monitor/device/getActivatedDeviceJson/" + TopMenu.CURRENT_TAB + "/";
this.loadTemplateAndFillUp(url, "#activatedDeviceTemplate", "#activatedDevice");
},
getDeActivatedDeviceList : function() {
var url = "/monitor/device/getDeactivatedDeviceJson/" + TopMenu.CURRENT_TAB + "/";
this.loadTemplateAndFillUp(url, "#deactivatedDeviceTemplate", "#deactivatedDevice");
},
getLostOrStolenDeviceList : function() {
var url = "/monitor/device/getLostOrStolenDeviceJson/" + TopMenu.CURRENT_TAB + "/";
this.loadTemplateAndFillUp(url, "#lostOrStolenDeviceTemplate", "#lostOrStolenDevice");
},
getWaitingDeviceList : function() {
var url = "/monitor/device/getWaitingDeviceJson/" + TopMenu.CURRENT_TAB + "/";
this.loadTemplateAndFillUp(url, "#waitingDeviceTemplate", "#waitingDevice");
},
loadTemplateAndFillUp : function(url, templateElement, appendElement) {
$.ajax({ //<!--This ajax call fires upon initialize function
url : url,
dataType : 'json',
beforeSend : function(xhr) {
$(appendElement).children(".zoom").attr("src", "/monitor/img/icon/loading.gif");
},
complete : function(xhr) {
setTimeout(
function() {
$(appendElement).children(".zoom").attr("src", "/monitor/img/btn/btn_zoom.png")
},
500
);
$(appendElement).find("table.dataBoxTable").tableScroll({height:DeviceManager.TABLE_HEIGHT});
DeviceManager.columnAutoFit(appendElement);
DeviceManager.addListenerAndHandler();
},
success : function(data) {
$(templateElement).tmpl(data).appendTo(appendElement); //<!--This jquery template get messed up by ajax arrival order.
},
async: true
});
},
I hope you could understand my English. thank you very much.