[英]How to call ajax again n again from service layer function of java class to show page number status?
碼:
function importData(pageForm, menuNavigationId, pageId)
{
showMessageHtml('messageDiv', "Importing data ........");
var url = getURLString(pageForm);
var urlstr = "importTemplate.do?userAction=importData&"
+ url.substring(0, url.length - 1);
ajaxFunction();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
document.getElementById('messageDiv').style.display = 'none';
if (xmlHttp.responseText == "success") {
alert("Data file read and saved successfully.");
} else {
alert("Error while Importing data: " + xmlHttp.responseText);
}
returnToPageUrl("page?pageId=" + pageId
+ "&opType=entry&modType=add&menuNavigationId="
+ menuNavigationId + "&menuPageId=" + pageId);
}
}
}
xmlHttp.open("POST", urlstr, true);
xmlHttp.setRequestHeader("Content-Type", "application/plain");
xmlHttp.send(null);
}
我要代替“正在導入數據........”,而是要顯示一個顯示頁碼的字符串。...您能幫我如何再次調用ajax n以獲取頁面狀態嗎? 我正在從服務層函數傳遞此字符串........需要盡快答復
使用setTimeout(方法,頻率);
其中method是您的Ajax調用,而frequency是您要再次調用ajax方法的時間段。
根據評論編輯:
假設您的ajax調用將調用一個servlet,然后在servlet中獲取響應的輸出流並向您寫入數據:
httpServletResponse.getOutputStream(10);
然后在您的JavaScript中,您可以像這樣訪問它:
xmlHttp.responseText
只需在您的頁面中顯示即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.