Ajax状态码是什么? 在创建Ajax对象,配置Ajax对象,发送请求,以及接收服务端响应数据,这个过程的每一个步骤对应一个数值,这个数值就是Ajax状态码
0 未初始化 1 请求已经建立但是还没有发送没有调用send 2 请求已经发送 3 请求正在处理中已经有部分可以用了 4 请求已经完成可以获取并使用服务器响应了
xhr
.readyState
onreadystatechange
var xhr
= new XMLHttpRequest;
xhr
.open('get', 'http://localhost/state');
xhr
.onreadystatechange = function () {
if (xhr
.readyState
== 4) {
console
.log(xhr
.responseText
);
}
}
xhr
.send();
}