ajax缓存问题

禁止ajax缓存问题:在ajax发送请求前加上xmlHTTP.setRequestHeader("If-Modified-Since","0");


<html>
<head>
<title>My first ajax programe</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript" type="text/javascript">
<!--
var xmlHTTP;
// =======================================
//  Function Name:creatXMLHTTP()
//  Function:Creat XMLHTTPRequest Object
// =======================================
function createXMLHTTP(){
    if(window.ActiveXObject) {
           xmlHTTP = new ActiveXObject('Microsoft.XMLHTTP'); //if IE
    }
    else if(window.XMLHTTPRequest){
       xmlHTTP = new XMLHTTPRequest();
    }
}
function getHTMLinfo(URL){
      
    createXMLHTTP();
          
    xmlHTTP.open("get", URL, true);
    xmlHTTP.onreadystatechange = callHTML;
    xmlHTTP.setRequestHeader("If-Modified-Since","0");
    xmlHTTP.send();
}
function callHTML(){
    if(xmlHTTP.readyState == 4){
       if(xmlHTTP.status ==200){
          alert("服务器返回信息:" + xmlHTTP.responseText);
          document.write(xmlHTTP.responseText); // 将加载html.htm到当前页面
       }
    }    
}
//-->
</script>
</head>
<body>
        <form name="frmTest" action="#">
    <input name="btnShowInfo" type="button" value="显示服务器返回信息" onclick="getHTMLinfo('http://localhost/html.htm')">
        </form>
</body>
</html>
posted @ 2009-07-20 09:46  94cool  阅读(179)  评论(0)    收藏  举报