//gfun.js //js create XMLHttpRequest function CreateXmlReq() { var objReq = false; try { objReq = new XMLHttpRequest(); } catch (tryMicrosoft) { try { objReq = new ActiveXObject("Msxml2.XMLHTTP"); } catch (otherMs) { try { objReq = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { objReg = false; } } } return objReq; } //ajax1.html <html> <head> <title> Test For Fist AJAX </title> </head> <mce:script type="text/javascript" src="gfun.js" mce_src="gfun.js"></mce:script> <mce:script type="text/javascript"><!-- var xmlHttp=null; function GetCustomInfo() { var strPhone = document.getElementById("phone").value; //var strUrl = "./ajax1.php?phone=" + escape(strPhone); var strUrl = "./ajax1.php"; var strQuery = "phone=" + escape(strPhone); alert("phone: " + strPhone + "/nurl: " + strUrl); xmlHttp = CreateXmlReq(); if (!xmlHttp) { alert("浏览器不支持!"); } xmlHttp.onreadystatechange=UpdatePage; xmlHttp.open("POST", strUrl, true); xmlHttp.send(strQuery); } function UpdatePage() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { alert("Server is done"); } else { alert("error - "+xmlHttp.status); } } } // --></mce:script> <body> <form name="testform" action="ajax1.php" method="POST"> <p> Please input your phone number:<br> <input type="text" size="14" name="phone" id="phone" onChange="GetCustomInfo();" /> </p> <p>Your order will be delivered to </p> <p>Type your order in here:</p> <p><textarea name="order" rows="6" cols="50" id="order"> <p><input type="submit" value="Order" id="submit" /></p> </form> </body> </html>