Discussion on the problem of Ajax browser compatibility

Source: Internet
Author: User

 ajax Browser compatibility problem has always been a lot of students worry about, here is a good example you can refer to, I hope to help you!

  Code as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  <html xmlns=" http://www.w3.org/1999/xhtml ">  <head>  <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/>  <title> Untitled document </title>  <script>  window.onload = function () {   var obtn = document.getElementById (' btn ');  Obtn.onclick = function () { //1. Create Ajax objects  // Only non-IE6 browsers   var oajax = null;  if (window) are supported. XMLHttpRequest) {  Oajax = new XMLHttpRequest (); //alert (new XMLHttpRequest ()); }else{ // Supports only IE6 browser   Oajax = new ActiveXObject ("Microsoft.XMLHTTP"); } . Connect the server, add a time parameter here, each access address is different, The browser does not use the buffer in the browser, but the  //But the server side is not resolved this time   Oajax.open ("Get", "a.txt?t=" + New Date (). GetTime (), true); //3. Send   oajax.send (null); //4. Accept information   Oajax.onreadystatechange = function () { //The interaction between the browser and the server, to whichStep, when equal to 4, the representative read completes the   if (oajax.readystate==4) { //status code, only equals 200, the representative accepts the completion, and succeeds the   if (oajax.status==200) {   Alert ("Success" + Oajax.responsetext); }else{  alert ("Failed"); } } };   }; } ;  </script>  </head>    <body>  <input type= "button" value= "button" id= "btn "/>  </body>  </html>   
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.