var xhr = new XMLHttpRequest();
xhr.open("get",url,true);
xhr.onreadystatechange = function() {
//载体自身的执行情况。
// xhr.readyState
//网络的状态
// xhr.status
if(xhr.readyState === 4 && xhr.status === 200){
//response是xhr一条属性,可以得到xhr的数据。
console.log(xhr.responseText);
}else if(xhr.readyState === 4 && xhr.status !== 200){
console.log(xhr.status);
}
}
xhr.send();//受限于get和post的传输方式,目前先为空。
//xhr载体
xhr.readyState :0~4.4表示成功
//http网络状态
xhr.status 除了200其他大部分就是失败。
//1**一般看不到一,因为还没有完成,我们看不到。
//2**200表示成功,其他表示其中的一个过程。
//3**完成了,但是可能差了一步。可能是警告。
//4**表示包含了一个错误。
//5**表示跟我们无关,表示服务器出了问题,找后端。