0
我有一組Ajax調用。而這些電話必須稱爲group by。 例如: 我需要按以下方式調用Ajax調用。ajax調用在執行同步加異步的情況下掛起
var ajaxCallListGroupBy = [["AjxStep_11", "AjxStep_12", "AjxStep_13"],["AjxStep_21", "AjxStep_22", "AjxStep_23"]];
一旦陣列阿賈克斯的第一個指數叫完了,我們需要調用數組Ajax調用第二個索引。
所以,我使用下面的機制來調用ajax調用。但是,頁面正在被絞死。
function callGroupByAjaxCalls(newIndex){
orderOneAjaxCount = 0;
var listOfQueries = ajaxCallListGroupBy[newIndex];
groupCalls = listOfQueries.length;
for (var currIndex=0,len=listOfQueries.length; currIndex<len; currIndex++){
window[listOfQueries[currIndex]]();
}
if(ajaxCallListGroupBy.length>1){//To check how many times we have to iterate
if(newIndex < (ajaxCallListGroupBy.length-1) && (orderOneAjaxCount >= ajaxCallListGroupBy[newIndex].length)){
callGroupByAjaxCalls(newIndex+1);
}else{
console.log("After 3 secs orderOneAjaxCount "+orderOneAjaxCount);
setTimeout(plsWait(newIndex),1000);
if(plsWait(newIndex)){
callGroupByAjaxCalls(index+1);
}
}
}else if(ajaxCallListGroupBy.length <= newIndex){//To check index already reached to actual calls
console.log("no need of further calls. Alreay all ajax calls hit from APP");
}else if(ajaxCallListGroupBy.length == newIndex){ //If there is only one set of ajax calls there
console.log("only one set of ajax calls. So no need to call any other ajax call");
}else{
console.log("handle new use case");
}
}
function plsWait(index){
var flg = true;
console.log("orderOneAjaxCount = "+orderOneAjaxCount+" ajaxCallListGroupBy[index].length ="+ajaxCallListGroupBy[index].length);
if(!(orderOneAjaxCount >= ajaxCallListGroupBy[index].length)){
for(l=0;l<20000;l++){
}
if(!(orderOneAjaxCount >= ajaxCallListGroupBy[index].length)){
plsWait(index);
}
}
return flg;
}
注:orderOneAjaxCount
將在每個Ajax調用遞增。
無法格式化。直到注意到,每件事情都是javascript代碼只有 –
你覺得哪裏可能是這個問題? –
你知道'setTimeout(plsWait(newIndex),1000);'在調用'plsWait()'之前沒有等待。它被立即調用。你必須傳遞一個函數引用(一個沒有parens的函數名)。 – jfriend00