//1.创建XML对象
var xhr = null;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();//IE6不兼容
} else {
xhr = new ActiveXObject("Microsoft.XMLHttp");//IE6独有创建XML对象方法
}
//2.建立连接
xhr.open("get","http://www.baidu.com")
//3.发送请求
xhr.send()
//4.监听readystate变化,即监听请求过程
xhr.onreadystatechange = function (){
if(xhr.readystate == 4 && xhr.status == 200){//xhr.readystate == 4 表示请求已完成 接收到请求结果
console.log(xhr.responseText);//xhr.responseText内存储请求成功的结果
}
}