81,092
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
function run(){
window.setInterval(ajaxAccess(),6000);
}
/*创建XMLHttpRequest的对象*/
var xmlhttp;
function ajaxAccess(){
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
/*执行回调函数*/
var responseValue;
xmlhttp.onreadystatechange = function(){
if(xmlhttp.status==200&&xmlhttp.readyState==4){
responseValue = xmlhttp.responseText();
if(responseValue!=null){
/*有内容变化时,给页面一个反馈*/
document.getElementById("testDiv").innerHTML = responseValue;
}
}
}
/*提交到一个action上去,action去访问数据库,加个判断,有内容就返回*/
var url = "";
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
</script>
<body onload="run()">
<div id="testDiv">数据库发生变化的话,把内容显示到这里</div>
</body>