1.post方法中,數據放在send()方法中,作爲參數傳遞
2.需要設置請求頭,用來指明編碼方式,發送的數據類型
3.post方式不會出現中文亂碼和瀏覽器緩存問題
var ajax=null; try { ajax=new XMLHttpRequest() }catch(e) { ajax=new ActiveXObject("Microsoft.XMLHTTP") } ajax.open("post","a.php",true) ajax.setRequestHeader("content-type","application/x-www-form-urlencoded") ajax.send("name=張三&age=20") ajax.onreadystatechange=function(){ if(ajax.readyState==4){ if(ajax.status==200){ console.log(ajax.responseText) } }else{ console.log(ajax.status) } }