终于睛天了.
一个AJAX局部刷新的例子:
前台页面:
<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>AJAX局部刷新</title>
<scripttype="text/javascript">
<!--
//建立XMLHttpRequest对象
varxmlhttp;
try{
xmlhttp=newActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp=newActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp=newXMLHttpRequest();
}catch(e){}
}
}
functiongetPart(url){
xmlhttp.open("get",url,true);
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
if(xmlhttp.responseText!=""){
document.getElementById("partdiv").innerHTML=unescape(xmlhttp.responseText);
}
}
else{
document.getElementById("partdiv").innerHTML="数据载入出错";
}
}
}
xmlhttp.setRequestHeader("If-Modified-Since","0");
xmlhttp.send(null);
}
setInterval("getPart('getPart.asp')",1000)
//-->
</script>
</head>
<body>
<divid="partdiv"></div><!--局部刷新数据的容器-->
</body>
</html>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>AJAX局部刷新</title>
<scripttype="text/javascript">
<!--
//建立XMLHttpRequest对象
varxmlhttp;
try{
xmlhttp=newActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp=newActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp=newXMLHttpRequest();
}catch(e){}
}
}
functiongetPart(url){
xmlhttp.open("get",url,true);
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
if(xmlhttp.responseText!=""){
document.getElementById("partdiv").innerHTML=unescape(xmlhttp.responseText);
}
}
else{
document.getElementById("partdiv").innerHTML="数据载入出错";
}
}
}
xmlhttp.setRequestHeader("If-Modified-Since","0");
xmlhttp.send(null);
}
setInterval("getPart('getPart.asp')",1000)
//-->
</script>
</head>
<body>
<divid="partdiv"></div><!--局部刷新数据的容器-->
</body>
</html>
后台页面:[getPart.asp]
<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>
<!--#includefile="conn.asp"-->
<%
dimrs
dimsql
Setrs=Server.CreateObject("ADODB.Recordset")
sql="select*fromking_test"
rs.opensql,conn,1,1
ifnot(rs.bofandrs.eof)then
Response.Write("<table>")
Response.Write(escape("<tr><td>ID</td><td>关键字</td></tr>"))
dowhilenotrs.eof
%>
<tr><td><%Response.Write(rs("id"))%></td><td><%Response.Write(escape(rs("keyword")))%></td></tr>
<%
rs.movenext
loop
Response.Write("</table>")
endif
rs.close
setrs=nothing
conn.close
Setconn=nothing
%>
<!--#includefile="conn.asp"-->
<%
dimrs
dimsql
Setrs=Server.CreateObject("ADODB.Recordset")
sql="select*fromking_test"
rs.opensql,conn,1,1
ifnot(rs.bofandrs.eof)then
Response.Write("<table>")
Response.Write(escape("<tr><td>ID</td><td>关键字</td></tr>"))
dowhilenotrs.eof
%>
<tr><td><%Response.Write(rs("id"))%></td><td><%Response.Write(escape(rs("keyword")))%></td></tr>
<%
rs.movenext
loop
Response.Write("</table>")
endif
rs.close
setrs=nothing
conn.close
Setconn=nothing
%>