ajax

window.onload = function(){
//1,创建一个ajax对象
var xhr = new XMLHttpRequest();
//2,创建一个新的http请求协议,并设置请求的服务端地址
var url = '/xx.php';
xhr.open('get',url);
//3,把http请求发送给服务器
xhr.send(null);//get请求时,此处为空
//4,获取返回的数据
xhr.onreadystatechange = function(){
if(xhr.readyState==4){
//var obj = JSON.parse(xhr.responseText);
document.getElementById('ajax').innerHTML = xhr.responseText;
//console.log(xhr.responseText);//打印出请求结果
}
};
};