This time I will bring you what are the basic common codes of ajax, and what are the precautions when using the basic common codes of ajax. The following is a practical case, let's take a look.
The examples in this article describe the basic general code of ajax. Share it with everyone for your reference, the details are as follows:
<html> <head> <script type="text/JavaScript"> var xmlhttp function loadXMLDoc(url) { // code for Mozilla, etc. if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() xmlhttp.onreadystatechange=state_Change xmlhttp.open("GET",url,true) xmlhttp.send(null) } // code for IE else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") if (xmlhttp) { xmlhttp.onreadystatechange=state_Change xmlhttp.open("GET",url,true) xmlhttp.send() } } } function state_Change() { // if xmlhttp shows "loaded" if (xmlhttp.readyState==4) { // if "OK" if (xmlhttp.status==200) { document.getElementById('T1').innerHTML=xmlhttp.responseText } else { alert("Problem retrieving data:" + xmlhttp.statusText) } } } </script> </head> <body onload="loadXMLDoc('test_xmlhttp.txt')"> <p id="T1" style="border:1px solid black;height:40;width:300"></p><br /> <button onclick="loadXMLDoc('test_xmlhttp2.txt')">Click</button> </body> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How does JSONP handle Ajax cross-domain access
Global monitoring of ajax operation, how to handle user session failure deal with
The above is the detailed content of What are the basic common codes for ajax?. For more information, please follow other related articles on the PHP Chinese website!