<html> <body> <script type="text/javascript"> var ajax = null; if(window.XMLHttpRequest){//建立Ajax對象 ajax = new XMLHttpRequest(); }else if(window.ActiveXObject){ ajax = new ActiveXObject("Microsoft.XMLHTTP"); } if(ajax){//若是建立Ajax對象成功 var url = "login.inc.php";//設置Ajax訪問的頁面路徑 var pStr = "username=root&pwd=root";//須要post的數據用&符號連接起來 ajax.open("POST",url ,true); ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//設置訪問的http頭 ajax.send(pStr);//提交數據 ajax.onreadystatechange = function(){ if(ajax.readyState == 4 && ajax.status == 200){ alert(ajax.responseText);//彈出php頁面的返回信息 } } }else{ alert("Create Ajax Fail");return false; } </body> </html>