简单的ajax的结构

 1 <script type="javascript">  
 2     var xmlHttpRequest=null; //生命一个空对象以接收XMLHttpRequest 对象  
 3   
 4     function ajaxSubmit()  
 5     {  
 6         //---------------造对象、发请求---------------------------  
 7         if(window.ActiveXObjext)//如果是ie  
 8         {  
 9             xmlHttpRequest=new XMlHttpRequest();  
10         }else if(window.XMLHttpRequest)//其他浏览器  
11         {  
12             xmlHttpRequest=new XMLHttpRequest();  
13         }  
14       
15         if(null!= xmlHttpRequest){  
16             //                        url请求的地址  
17             xmlHttpRequest.open("get","url",true);  
18             //关联号ajax的回调函数      |下面的这个值改变了 ajaxCallbacky会被调用      *一次请求会被调用四次  
19             xmlHttpRequest.onreadystatechange=ajaxCallback;  
20             //真正的向服务器端发送数据  
21             xmlHttpRequest.send(null);  
22         }  
23           
24         //------------------相应事件,一次请求此事件会被调用四次------------------------  
25         function ajaxCallback(){  
26             if(xmlHttpRequest.readyState==4)  
27             {  
28                 if(xmlHttpRequest.ststus==200)  
29                 {  
30                     var responseText=xmlHttpRequest.responseText;  
31                     document.getElementById("div1").innerHTML=responseText;  
32                 }  
33             }  
34         }  
35     }  
36   
37 </script>  

 Ajax Post 与 Get 实例   http://www.nowamagic.net/ajax/ajax_ExamplesOfPostAndGet.php

原文地址:https://www.cnblogs.com/laj12347/p/2962595.html