0

I was trying to define a timeout of 1 hour for a xmlHttpRequest with below code, but alert could not generate . Is there any specific limit of timeout beyond which we can not set the timeout for an asynchronous request with xmHttprequest object.

Please suggest if i want to set timeout for long time as my server goes to reboot due to which i have to wait for that much long time. And is there any other alternative in which i can define longer timeout.

Below code is working fine in IE8 if i set timeout to 12000 milliseconds. But did not work when timeout is 1 hour.

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