終於睛天了.
一個AJax局部刷新的例子:
前台頁面:
<%@LANGUAGE="VBSCRipT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHtml 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html XMLns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/Html; charset=utf-8" />
<title>AJax局部刷新</title>
<script type="text/Javascript">
<!--
//建立XMLhttpRequest對象
var XMLhttp;
try{
xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp= new XMLHttPRequest();
}catch(e){}
}
}
function getPart(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>
<div id="partdiv"></div><!--局部刷新數據的容器-->
</body>
</Html>
後台頁面:[getPart.ASP]
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="conn.ASP"-->
<%
dim rs
dim sql
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select * from king_test"
rs.open sql,conn,1,1
if not (rs.bof and rs.eof) then
Response.Write("<table>")
Response.Write(escape("<tr><td>ID</td><td>關鍵字</td></tr>"))
do while not rs.eof
%>
<tr><td><%Response.Write(rs("id"))%></td><td><%Response.Write(escape(rs("keyWord")))%></td></tr>
<%
rs.movenext
loop
Response.Write("</table>")
end if
rs.close
set rs = nothing
conn.close
Set conn = nothing
%>