xmlHttp的问题

来源:百度知道 编辑:UC知道 时间:2024/05/19 16:18:06
最近做一个程序,用到了xmlHttp,自动读取一个xml文件并显示在<ul>里,可是测试的时候发现只读一次, 此时我测试window.setTimeout是正常运行
代码如下:
<script language="javascript" type="text/javascript">
function setTimers()
{
var xmlHttpReq= new ActiveXObject("MSXML2.XMLHTTP");
xmlHttpReq.open("GET", "http://localhost:34232/zxft/chatFile.xml");
var element=document.getElementById("chatmsg");
xmlHttpReq.onreadystatechange = function()
{
if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200 )
{ element.innerHTML=xmlHttpReq.responseText;
}
}
xmlHttpReq.send();
window.setTimeout(setTimers,1000);
}

xmlHttpReq.open("GET", "http://localhost:34232/zxft/chatFile.xml");
这个原因是当每次请求的URL一样时低版本的一些浏览器会自动过滤掉,
你可以这样,在这http://localhost:34232/zxft/chatFile.xml后面加上一个参数,他的值为每次重新生成的一个随机数,用于区分每次的请求
如:“http://localhost:34232/zxft/chatFile.xml”+“&i=”+随机数