window.onload = function(){
document.getElementById('btn').onclick = function(){
var req = new XMLHttpRequest();
req.open('get', 'demo.php'); //建立服务器连接 get 或 post请求
req.onreadystatechange = function(){ //ajax请求状态变化
if(req.readyState == 4 && req.statu == 200){ //200状态表示返回成功
var str = req.responseText;
alert(str)
}
}
req.send();//对服务器发送请求
}
}