在项目中xmlhttp,我的使用

来源:互联网 发布:软件外包需求 编辑:程序博客网 时间:2024/03/29 18:09


<HTML>
<HEAD>
<script>
function test()
{
   var xmlHttp,strData;
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttp.open("post","http://130.54.1.10:7001/unicom/StatusServlet",false);
    xmlHttp.send();
    strData=xmlHttp.responseText;
    form1.age.value=strData;
     document.all("div2").

    document.all("div1").innerHTML=strData;

    setTimeout("test()",3000);
 }

 
</script>
<TITLE> New Document </TITLE>
</HEAD>

<BODY onload="test()">
<form name="form1" action="">
<input type="text" name="age" size="15">
</form>

<div id="div1">

</div>
</BODY>
</HTML>

在对应的servlet中,对头文件的设置很重要,可以去掉缓存里面的数据。

public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
                   throws IOException, ServletException
  {
    response.setHeader("Pragma","no-cache");
    response.setHeader("Cache-Control","no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("text/html;charset=gb2312");

}


原创粉丝点击