<script type=”text/javascript”> function getXMLHttpRequest() { var xhr = false; if ( window.XMLHttpRequest ) { xhr = new XMLHttpRequest(); if ( xhr.overrideMimeType ) { xhr.overrideMimeType(”text/xml”); } }else if ( window.ActiveXObject ) { try{ xhr = new ActiveXObject(”Msxml2.XMLHTTP”); }catch(e) { try{ xhr = new ActiceXObject(”Microsoft.XMLHTTP”); }catch(e) { xhr = false; } } } return xhr; } window.onload = function() { var _x = getXMLHttpRequest(); //获得XMLHttpRequest对象 if ( !_x ) return false; _x.open(”get”,http://www.baidu.com,true); _x.onreadystatechange = function() { if ( _x.readyState == 4 && _x.status == 200 ) { clearTimeout(clearTO); //如果准备状态成功,并且HTTP状态码正确则清除setTimeout alert(”Success”); } }; var cleaeTO = setTimeout(function() /*重点,在请求发布后开始设置setTimeout,如果请求状态不成功也就是readyState != 4 那么setTimeout将会在5秒后运行,并弹出信息提示,要是请求成功,将会清除该setTimeout*/ { _x.abort(); //终止XMLHttpRequest对象 alert(”系统异常,请您刷新页面或稍后再试….”); },50000); _x.send(null); }; </script>