Discussion of Ajax browser compatibility _ajax related

Source: Internet
Author: User

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>

Related Article

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.