UPDATE: Here is an example of how you can handle the timeout:
var xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET", "http://www.example.com", true); xmlHttp.onreadystatechange=function(){ if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { clearTimeout(xmlHttpTimeout); alert(xmlHttp.responseText); } }
In IE8, you can add a timeout XMLHttpRequest event handler.
var xmlHttp = new XMLHttpRequest(); xmlHttp.ontimeout = function(){ alert("request timed out"); }
I would recommend not making synchronous calls like your code, and also recommend using the javascript framework for this. jQuery is the most popular. This makes your code more efficient, easier to maintain, and cross-browser compatible.
Jose Basilio Jun 19 '09 at 15:55 2009-06-19 15:55
source share