我有这样的代码 - 它基本上会调用AJAx,然后显示对话框。当收到AJAX调用对话框的响应时,将更新结果或错误。它工作正常,直到这里。但是,如果AJAX调用发生超时,则会在对话框中显示错误消息,然后立即刷新页面(并且不会触发对话框的关闭操作)。不确定如何在超时的情况下停止页面的自动刷新。任何建议或意见都非常感谢。感谢。
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");
}
});
答案 0 :(得分:0)
AJAX超时不应导致页面刷新。也许还有其他原因造成这种情况。也许location.reload()
?