<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
console.dir(XMLHttpRequest);
//通过上面这行代码,可以看到几个关键信息(DONE:4、LOADING:3、HEADERS_RECEIVED:2、OPENED:1、UNSENT:0)
var xhr = new XMLHttpRequest();
console.log(xhr);
//可以看到一系列属性和方法
xhr.open("get","http://jsonplaceholder.typicode.com/users",true);
xhr.onreadystatechange=function(){
console.log(xhr.readyState);
//可以看到状态码的变化
if(xhr.readyState==4&&xhr.status==200){
//console.log(xhr.responseText);
}
}
xhr.send(null); //建立连接后,需发送请求
</script>
</body>
</html>