Ajax入门例子
发布时间:2020-12-16 00:16:33 所属栏目:百科 来源:网络整理
导读:在customer.php的文件中,代码如下: html head script type="text/javascript" function showCustomer(str) { var xmlhttp; if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+,Fir
在customer.php的文件中,代码如下: <html> <head> <script type="text/javascript"> function showCustomer(str) { var xmlhttp; if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+,Firefox,Chrome,Opera,Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6,IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET","/test/getcustomer.php?q="+str,true);//这里的url是指你的文件路径,例如,我的customer.php和getcustomer.php都在www下的test文件 目录下,所以就写成了此种形式 xmlhttp.send(); } </script> </head> <body> <form action="" style="margin-top:15px;"> <label>请选择一位客户: <select name="customers" onchange="showCustomer(this.value)" style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <option value="APPLE">Apple Computer,Inc.</option> <option value="BAIDU ">BAIDU,Inc</option> <option value="Canon">Canon USA,Inc.</option> <option value="Google">Google,Inc.</option> <option value="Nokia">Nokia Corporation</option> <option value="SONY">Sony Corporation of America</option> </select> </label> </form> <br /> <div>客户信息将在此处列出 ...</div> <div id="txtHint"></div> </body> </html> 在getcustomer.php的文件中,代码如下:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |