我正在調用一個函數在一個循環中,使ajax調用。我需要等待1個Ajax呼叫才能再次撥打電話。該代碼是喜歡 -如何等待1 ajax調用結束進行另一個Ajax調用循環?
function chkAll(field, markr) {
var string = "document.forms[0].pCheckBox" + markr + ".checked";
var temp = eval(string);
if (temp) {
if (field.length > 1) {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
decide(field[i].id, field[i].value);
}
}
else {
field.checked = true;
decide(field.id, field.value);
}
}
}
即拍即Ajax調用的函數如下:
function decide(code, dataString) {
if (document.getElementById(code).checked) {
var url = "../PRODUCT/PCProcess_Ajax.jsp?CIMS_CSRFTOKEN=" + getTokenFromSessionId();
if (window.ActiveXObject) {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
}
httpRequest.open("POST", url, true);
httpRequest.onreadystatechange = processRequest;
httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
varparameters = "pScreenId=ClmReports&pEventCode=NFACREATE&pDataString=" +
dataString + "&pSelectName=" + code;
httpRequest.send(parameters);
} else {
var url = "../PRODUCT/PCProcess_Ajax.jsp?CIMS_CSRFTOKEN=" + getTokenFromSessionId();
if (window.ActiveXObject) {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
}
httpRequest.open("POST", url, true);
httpRequest.onreadystatechange = processRequest;
httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var parameters = "pScreenId=ClmReports&pEventCode=NFADELETE&pDataString=" + dataString;
httpRequest.send(parameters);
}
}
在
processRequest()
我只是存儲httpRequest.responseText
並使用它。我想要確保一個decide()
被稱爲在完成1之後。
此視圖中的任何視圖?
使用jQuery,它使這個過程很容易 – Nayish
抱歉,不能使用jquery.this是exixting產品代碼。 – Kaustav