xrget()超时会导致自动刷新页面.如何阻止这种情况



我有这样的代码——它基本上进行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");
    }
});

AJAX timout不应该导致页面刷新。也许是其他原因造成的。也许location.reload()

相关内容

  • 没有找到相关文章

最新更新