使用AJAX自动定时无闪动更新页面数据

 test.jsp

 

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DWR测试</title>
  <script type="text/javascript" src='<%= request.getContextPath() %>/dwr/interface/bu.js'></script>
  <script type='text/javascript' src='<%= request.getContextPath() %>/dwr/engine.js'></script>
  <script type='text/javascript' src='<%= request.getContextPath() %>/dwr/util.js'></script>
</head>
<script>
var i=0;
function init()
{   
   
window.setInterval('Check()',5000);
//每隔5秒自动调用Check()   
}

function Check()
{

var trobj=document.getElementById("1");
trobj.cells(1).innerText="风调雨顺"+i;
i++;
}

</script>
<body onload="init()">
本程序,在指定表格内使用AJAX,每5秒无闪动更新表格中“风调雨顺”

 

<form action="" name="post">
<table id="news" cellspacing="2" cellpadding="2" align="center" border="2" bgcolor="#c0c0c0">
<tr>
<td width="15%">名称</td><td width="55%">内容</td>
</tr>
<tr id="1">
<td>国内</td><td>风调雨顺</td><td></td>
</tr>
<tr id="2">
<td>国外</td><td>地震不断</td><td></td>
</tr>
<tr id="3">
<td>世界</td><td>风景这边最好</td><td></td>
</tr>
</table>

</form>


</body>

</html>

你可能感兴趣的:(JavaScript,html,jsp,Ajax,DWR)