欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
Aajx中onreadystatechange的属性含义
 
readyState 属性存留 XMLHttpRequest 的状态。
 
onreadystatechange 属性定义当 readyState 发生变化时执行的函数。
 
status 属性和 statusText 属性存有 XMLHttpRequest 对象的状态。
 
属性 描述
onreadystatechange 定义了当 readyState 属性发生改变时所调用的函数。
readyState
保存了 XMLHttpRequest 的状态。
 
0: 请求未初始化
1: 服务器连接已建立
2: 请求已接收
3: 正在处理请求
4: 请求已完成且响应已就绪
status
200: "OK"
403: "Forbidden"
404: "Page not found"
如需完整列表,请访问 Http 消息参考手册
 
statusText 返回状态文本(例如 "OK" 或 "Not Found")
每当 readyState 发生变化时就会调用 onreadystatechange 函数。
 
当 readyState 为 4,status 为 200 时,响应就绪:
 
实例
function loadDoc() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("demo").innerHTML =
            this.responseText;
       }
    };
    xhttp.open("GET", "ajax_info.txt", true);
    xhttp.send(); 
 
注释:onreadystatechange 被触发五次(0-4),每次 readyState 都发生变化。

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64527.shtml