< script >
//复杂方法,添加了很多检测,和错误处理
var xmlhttp,alerted,i=0;
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
alert("请安装Microsofts XML parsers")
}
}
if (!xmlhttp && !alerted) {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
alert("你的浏览器不支持XMLHttpRequest对象,请升级");
}
}
function getClock()
{
if (xmlhttp) {
xmlhttp.Open("Get","http://post.baidu.com/f?kz=139734716",true);
xmlhttp.onreadystatechange=RSchange;
xmlhttp.send();
}
}
setInterval( "getClock()", 80 );
function RSchange()
{
if (xmlhttp.readyState==4) {
//myTime.value = xmlhttp.responseText;
//myTime1.innerHTML = xmlhttp.responseText;
i++
myTime1.innerHTML = i;
}
}
< /script >
<body onLoad=getClock();>
<div id="myTime1"></div>
关闭窗口 来源:网络 16 2007-05-08