xmlhttp是非常好的一个组件,我们一般用它来做小偷程序,可以实现无数据库抓取对方内容显示,还可以用于生成HTML静态页面,还可以在HTML静态页面上实现动态内容显示。
用xmlhttp组件,通过get或post方式请求远程页面数据,实现无需刷新页面更新数据动态显示。
测试文件有两个,一个名为list.asp(请求页),另一个为msg.asp(内容页)。
list.asp内容如下:
function GetUserList()
{
oXMLHttpRequest = null;
szUserList = null;
var oXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
oXMLHttpRequest.Open("get", "msg.asp", false);
oXMLHttpRequest.setRequestHeader("Content-Type","text/html")
oXMLHttpRequest.Send();
szUserList = oXMLHttpRequest.responseText;
UserList.innerHTML = szUserList;
delete oXMLHttpRequest;
window.setTimeout("GetUserList()",5000);
//刷新时间5000毫秒(5秒),间隔时间可以自己调。
}
msg.asp内容如下
response.contenttype = "text/html"
response.charSet = "GB2312"
response.expires = 0
response.expiresabsolute = now() - 1
response.addHeader "pragma","no-cache"
response.addHeader "cache-control","private"
response.cachecontrol = "no-cache"
response.write "现在时间为:"&now()
%>
青岛星网温馨提醒:很多朋友从网上取例子直接拿来用,结果不成功,多数原因是远程页面(msg.asp)没有清空页面缓存(一定要加no-cache属性),所以请求的数据总是无法更新。