用AJAX刷新一个DIV中的jsp内容

<script type="text/javascript"> 

var xmlhttp; 

function startrefresh(){ 

xmlhttp=new XMLHttpRequest(); 

xmlhttp.open("POST,"ss.jsp",true); 

xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 

//xmlhttp.send("name=wk");  --需要传输参数时增加

xmlhttp.onreadystatechange = function(){ 

   if(xmlhttp.readyState == 4) 

        if(xmlhttp.status == 200) 

            document.getElementById("mydvi").innerHTML=xmlhttp.responseText; 

 } 

 } 

</script>

 

如果让这个div自动刷新的话,可以用setInterval('startrefresh()',5000),这个函数的作用是每隔5秒自动执行一次startrefresh方法,还有一种方法是setTimeout('startrefresh()',5000),但是这个方法只会执行一次。

 

 

上一篇:Qt编写文件一键命名软件


下一篇:内附PPT下载 | 性能为MySQL 10倍!阿里云重磅推出云原生数据仓库AnalyticDB基础版