<html> <head> <title>hello ajax</title> <script> var xmlRequest=null; function hint(content) { if(window.XMLHttpRequest) { xmlRequest=new XMLHttpRequest(); } else if(window.ActiveXObject) { xmlRequest=new ActiveXObject("Microsoft.XMLHTTP"); } var url="helloAjax.PHP?name="+content+"&q="+Math.random(); xmlRequest.onreadystatechange=stateChanged ; xmlRequest.open("GET",url,true); xmlRequest.send(null); } function stateChanged() { if (xmlRequest.readyState==4 || xmlRequest.readyState=="complete") { document.getElementById("targetDiv").innerHTML=xmlRequest.responseText; } } </script> </head> <body> hello ajax:<input type="text" id="inputField" name="txt" onkeyup="hint(this.value)"> <div id="targetDiv"></div> </body> </html>
helloAjax.PHP
<?PHP echo $_GET["name"]; ?>
原文链接:https://www.f2er.com/ajax/166292.html