posts - 37,  comments - 9,  trackbacks - 0

XMLHttpRequest的readyState:

0:未初始化——创建

1:初始化——open

2:发送请求——send

3:开始接受结果

4:接收结果完毕

状态每改变一次,调用一次回调函数。方法调用5次,但是前两次的readyState==1

 

onreadystatechange = callback

绑定回调函数,不加()。

 

XMLHttpRequest的status:

200 OK

404 Not Found

500 Serevr Error

 1 var xmlHttpRequest;
 2     
 3     //创建XMLHttpRequest对象
 4     function createXmlHttpRequest() {
 5         var xmlHttp;
 6         if(window.ActiveXObject) {
 7             try {
 8                 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
 9             } catch (e) {
10                 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
11             }
12         }else if(window.XMLHttpRequest) {
13             xmlHttp = new XMLHttpRequest()
14         }
15         
16         return xmlHttp;
17     }
18     
19 
20     function checkExist() {
21         xmlHttpRequest = createXmlHttpRequest();
22         xmlHttpRequest.onreadystatechange = callBack;
23         
24         var url = "http://localhost:8080/Ajax/CheckUser?uname="+document.getElementById("userName").value;
25         
26         xmlHttpRequest.open("GET", url, true);
27         xmlHttpRequest.send(null);
28     }
29     
30     function callBack() {
31         if(xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200) {
32             var result = xmlHttpRequest.responseText;
33             //
34         }
35     }
posted on 2011-03-14 15:36 wawlian 阅读(207) 评论(0)  编辑  收藏 所属分类: Ajax

只有注册用户登录后才能发表评论。


网站导航:
 

<2011年3月>
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜