Ajax request canceled before specified timeout

I am using ajax to fetch data from server. If I do not receive any response from the server within the specified time; then I want to execute a timeout handler. I need to set this timeout value to 60 seconds. But I see different behavior for different browsers as shown below:

IE9 will execute a timeout handler if the specified timeout is up to 40 seconds. If the timeout value is increased to 60; IE9 does not execute timeout handler. In IE9 Debug Tool I can see that the request is aborted after 40 seconds, even if the timeout is specified as 60 seconds.

The same is true for mozilla.

Chrome will execute a timeout handler if the specified timeout is 20 seconds. If the timeout value is increased to 30; chrome does not execute a timeout handler.

This is how I send ajax requests:

 http_request = new XMLHttpRequest();
 http_request.open('GET', url, true);

 http_request.ontimeout = function()
 { 
   timeoutaction(http_request); // function to execute when timeout occurs

 };


 http_request.onreadystatechange = function() 
 { 
      processContents(http_request); // function to execute onreadystatechange 
 };


 http_request.timeout = 60000;// Timeout value -- 60 seconds

 http_request.send(null);

      

Thank,

Swapnil

+3


source to share





All Articles