XMLHttpRequest——这是什么、怎样完整地执行一次GET请求、怎样检测错误。

XMLHttpRequest 对象提供了在网页加载后与服务器进行通信的方法。

 1 <script type="text/javascript">
 2     var xmlhttp;
 3     function loadXMLDoc(url){
 4         xmlhttp = null;
 5         if(window.XMLHttpRequest){    //code for all new browsers
 6             xmlhttp=newXMLHttpRequest();
 7         }elseif(window.ActiveXObject){    //code for IE5 and IE6
 8             xmlhttp=newActiveXObject("Microsoft.XMLHTTP");
 9         }
10         if(xmlhttp!=null){
11             xmlhttp.onreadystatechange=state_Change;
12                xmlhttp.open("GET",url,true);
13             xmlhttp.send(null);
14         }else{
15             alert("Your browser does not support XMLHTTP.");
16         }
17 }
18 
19 function state_Change(){
20     if(xmlhttp.readyState==4){    //4 = "loaded"
21         if(xmlhttp.status==200){    //200 = OK
22             //...our code here...
23         }else{
24             alert("Problem retrieving XML data");
25         }
26     }
27 }
28 </script>
原文地址:https://www.cnblogs.com/dtdxrk/p/2599542.html