Javascript利用xmlhttp获得服务器时钟
code.asp
---------------------------
<%
Response.Expires = -1
dim a
a=now()
Response.Write formatdatetime(a,2) & " " & formatdatetime(a,3)
%>
---------------------------
mytime.htm
---------------------------
<table><tr>
<td >时间</td>
<td >
<input type="text" id="myTime">
</td>
</tr>
</table>
<script>
var xmlhttp,alerted
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","clock.asp",true);
xmlhttp.onreadystatechange=RSchange;
xmlhttp.send();
}
}
setInterval( "getClock()", 1000 );
function RSchange()
{
if (xmlhttp.readyState==4) {
if(xmlhttp.statue==200){
myTime.value = xmlhttp.responseText;
}else {alert("异常!");
}
}
}
</script>
这是从网上找的代码,运行时不能显示时间。
Javascript利用xmlhttp,还需要什么设置吗?