1
我有這樣的代碼 - 它基本上使AJAx調用,然後顯示對話框。當AJAX調用收到響應對話框時,將更新結果或錯誤。它工作正常,直到這裏。但是,如果AJAX調用發生超時,則會在對話框中顯示錯誤消息,然後立即刷新頁面(並且不會觸發對話框的關閉操作)。不知道如何在超時的情況下停止自動刷新頁面。任何建議或意見都非常感謝。謝謝。dojo.xhrget()超時會導致自動頁面刷新。如何阻止?
var mainNode = dojo.create("div",{id:"mainNode"});
var brNode = dojo.create("div",{innerHTML:"<br><br>"})
var resultNode = dojo.create("div", {id:"resultNode",innerHTML:"Copying..."});
var infoNode = dojo.create("div", {id:"infoNode"});
dojo.style(mainNode, "width","700px");
dojo.style(mainNode, "height","auto");
mainNode.appendChild(infoNode);
mainNode.appendChild(brNode);
mainNode.appendChild(resultNode);
var timeoutStr = nlsVar.FILEPUB_EXTENSION.TIMEOUT;
var timeoutVal = parseInt(timeoutStr);
console.log('timeout value ' + timeoutVal);
dojo.xhrGet({
// The following URL must match that used to test the server.
url: "/BpFilePublisher/bpfilepub",
handleAs: "json",
timeout: timeoutVal, // Time in milliseconds
preventCache: true,
// The LOAD function will be called on a successful response.
load: function(response, ioArgs) { //
var str = json.jsonBeanStringify(response);
var infoNode = dojo.byId("infoNode");
infoNode.innerHTML = response[0].info;
var resultNode = dojo.byId("resultNode");
resultNode.innerHTML = response[0].result;
dojo.style(resultNode, "backgroundColor", "lightgreen");
dojo.style(resultNode, "border", "1px green");
},
// The ERROR function will be called in an error case.
error: function(error, ioArgs) { //
console.log('error' + error);
console.log('error.responseText' + error.responseText);
var resultNode = dojo.byId("resultNode");
if (error.responseText)
resultNode.innerHTML = error.responseText;
else {
resultNode.innerHTML = 'Timeout occured. Please try again';
isTimeout = true;
}
dojo.style(resultNode, "backgroundColor", "red");
dojo.style(resultNode, "border", "1px");
},
// Input parameters to the servlet
content: {fileName: fileName, fileId: fileId, srcCommUuid: srcCommId, bpCommId: bpCommUuid, action:action }
});
var dialogBundle = lconn.core.DialogUtil.popupForm(
nlsVar.FILEPUB_EXTENSION.COPYINTERNAL_DIALOG_TITLE,
mainNode,
'',
nlsVar.FILEPUB_EXTENSION.CANCEL_BUTTON_TITLE,
function() {
},
function() {
dialogBundle.hide();
location.reload();
}
);
dojo.addClass(dialogBundle._dialog.lotusSubmitNode, "lotusHidden");
dojo.addClass(dialogBundle._dialog.lotusBorderNode, "mydialog");
}
});