AJAX 局部刷新

[ 2007-08-14 13:55:41 | Author: zhenhua ]
Font Size: Large | Medium | Small
<script>
setInterval("refreshTime()",1000); //每格1秒刷新一次
funciton refreshTime()
{
 var dateObj = new Date();
 time.innerHTML = dateObj.toLocaleDateString(); //刷新div里面的内容
}
</script>
<div id=time></div>

------------------------------------------------------------------------------------------------------------------------------------

function doRef()
{
var url = "xxx.asp?a=1&b=2"
var dateRequest = new ActiveXObject("Microsoft.XMLHTTP");
dateRequest.abort() ;
dateRequest.open( "GET", url , true );
dateRequest.onreadystatechange = onSendSelf ;
dateRequest.send() ;
function onSendSelf()
{
if( dateRequest.readyState != 4 )
{
return ;
}
var theDate = dateRequest.responseText ;//如果出现编码问题,可以在服务端escape一下,然后在这里使用unescape( responseText )
theDiv.innerHTML = theDate ;
}
}
setInterval( doRef , 1000 ) ;//1秒刷新一次是不是快了点?

Comments Feed Comments Feed: http://www.zhenhua.org/feed.asp?q=comment&id=478
UTF-8 Encoding Trackback URL: http://www.zhenhua.org/trackback.asp?id=478

There is no comment on this article.

If you feel this site you find this information helpful, please click on the donation, which is voluntary,Thank you.
Post Comment
Smilies
[arrow] [biggrin] [confused] [cool]
[cry] [eek] [evil] [exclaim]
[frown] [idea] [lol] [mad]
[mrgreen] [neutral] [question] [razz]
[redface] [rolleyes] [sad] [smile]
[surprised] [twisted] [wink]
Enable UBB Codes
Auto Convert URL
Show Smilies
Hidden Comment
Username:   Password:   Register Now?
Security Code * Please Enter the Security Code