Solve the problem of Ajax caching

Source: Internet
Author: User

Add Xmlhttp.setrequestheader ("If-modified-since", "0") before Ajax sends the request;
In the URL home a random number of what, I used the next, not very good.

The specific code is as follows:

Here's the code:


<title>my-A-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 ("Server return information:" + xmlhttp.responsetext);
document.write (Xmlhttp.responsetext); Will load html.htm to the current page
}
}
}
-->
</script>

<body>
<form name= "Frmtest" action= "#" >
<input name= "Btnshowinfo" type= "button" value= "Display server return information" >
</form>
</body>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.