Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv=" Content-type " Content= "text/html; Charset=utf-8 "/>
<title> Untitled document </title>
<script>
window.onload = function () {
V Ar obtn = document.getElementById (' btn ');
Obtn.onclick = function () {
//1. Create Ajax Objects
//support only non-IE6 browsers
var oajax = null;
if (window. XMLHttpRequest) {
Oajax = new XMLHttpRequest ();
//alert (new XMLHttpRequest ());
}else{
//only supports the IE6 browser
Oajax = new ActiveXObject ("Microsoft.XMLHTTP");
}
//2. Connect the server, here add a time parameter, each access address is different, the browser does not use the buffer in the browser, but
//But the server that end is not resolved this time
Oajax.open ("Get", "a.txt?t=" + NE W Date (). GetTime (), true);
//3. Send
Oajax.send (null);
//4. Accept information
Oajax.onreadystatechange = FunctioN () {
//the interaction between the browser and the server, to what step, when equal to 4, the read completed
if (oajax.readystate==4) {
//status code, only equal to 200, the representative accepted completion, and succeeded
if (oajax.status==200) {
Alert ("Success" + Oajax.responsetext);
}else{
Alert ("failed");
}
}
};
};
};
</script>
<body>
<input type= "button" value= "button" id= "Btn"/>
</body>