Rumah >pembangunan bahagian belakang >tutorial php >php AJAX实例根据邮编自动完成地址信息_PHP
Ajax
<script> <BR>function createRequestObject() { <BR>var ro; <BR>var browser = navigator.appName; <BR>if(browser == "Microsoft Internet Explorer"){ <BR>ro = new ActiveXObject("Microsoft.XMLHTTP"); <BR>}else{ <BR>ro = new XMLHttpRequest(); <BR>} <BR>return ro; <BR>} <BR>var http = createRequestObject(); <BR>function sndReq(zip) { <BR>http.open('get', 'zipcode.PHP?zip='+zip); <BR>http.onreadystatechange = handleResponse; <BR>http.send(null); <BR>} <BR>function handleResponse() { <BR>if(http.readyState == 4){ <BR>var response = http.responseText; <BR>var update = new Array(); <BR>if(response.indexOf('|' != -1)) { <BR>update = response.split('|'); <BR>document.getElementById("city").value = update[0]; <BR>document.getElementById("state").value = update[1]; <BR>} <BR>} <BR>} <BR></script>Enter Zipcode: | |
City: | |
State: |