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();//對服務器發送請求
}
}php