AJAX

http://www.runoob.com/ajax/ajax-tutorial.html

 

防止自己忘记:

 1 var request1;
 2 if(window.XMLHttpRequest()) //如果浏览器支持
 3 {
 4     request1 = XMLHttpRequest();
 5 }else{                       //如果不支持
 6     request1 = new ActiveXObject('Microsoft.XMLHTTP');
 7 }
 8 
 9 
10 request1.onreadystatechange( ) = function(){
11     if(request1.readyState == 4){  //如果成功
12         if(request1.status == 200){   //如果成功,用 responseText 拿到文本内容 
13              return dowhensuccess(request1.responseText);
14         }else{
15             return dowhenfail(request.status);
16         }
17     }else{
18         //http请求继续!
19     }
20 }
21 
22 request1.open('GET','catagories',true);
23 request1.send();
24 
25 alert('请求已发送,请等待响应');
26 
27 
28 xmlhttp = new XMLHttpRequest();
29 
30 mxlhttp.onreadystatechange = function(){
31     if(xmlhttp.readyState=4 && xmlhttp.status=200){
32         docment.getElementById('myDiv').innerHTML=xmlhttp.responseText;
33     }
34 }

 

posted @ 2018-08-31 11:12  3532  阅读(62)  评论(0编辑  收藏  举报