0

我试图xmlHttpRequest用下面的代码为 a 定义 1 小时的超时,但警报无法生成。是否有任何特定的超时限制,超出该限制我们无法为带有xmHttprequest对象的异步请求设置超时。

请建议我是否想在我的服务器重新启动时长时间设置超时,因此我必须等待很长时间。还有其他选择可以定义更长的超时时间吗?

如果我将超时设置为 12000 毫秒,下面的代码在 IE8 中运行良好。但是当超时为 1 小时时不起作用。

var reqObject = null;

if ( window.XMLHttpRequest ) {
    // Except old version IE
    reqObject = new XMLHttpRequest();
} else if ( window.ActiveXObject ) {
    // For old version IE
    try {
        reqObject = new ActiveXObject( "Msxml2.XMLHTTP" );
    } catch ( e ) {
        try {
            reqObject = new ActiveXObject( "Microsoft.XMLHTTP" );
        } catch ( e ) {
            // cannot get object.
        }
    }
}

reqObject.open( "POST", url, true );
reqObject.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" );

reqObject.onreadystatechange = function() {
    try {
        if ( reqObject.readyState == 4 ) {
            if ( reqObject.status == 200 ) {
                // successful
                func( reqObject.responseText );
            } else {
                // error
                errfunc( reqObject.statusText );
            }
        }
    } catch ( e ) {
        // On some browsers, you may encounter the following exception.
        //  -->NS_ERROR_NOT_AVAILABLE
        // I saw it on Firefox(ver 3.6).
        // For more information, print 'e.message'.
        var errMsg;

        if ( e.name == JSERR_NS_ERROR_NOT_AVAILABLE ) {
            errMsg = "Cannot Connect";
        } else {
            errMsg = "Cannot Connect.";
        }

        // error
        errfunc( errMsg );
    }
}

reqObject.timeout = 3600000;
reqObject.ontimeout = function () {
    alert("Update process has Timed out.\nPlease check whether management node is up or not!!!");
}
reqObject.send( param );
4

0 回答 0