欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php AJAX实例根据邮编自动完成地址信息_PHP教程

程序员文章站 2022-03-22 15:22:40
...

Enter A United States Zipcode, Then Tab















Enter Zipcode:
City:
State:

以上是客户输入页面,下面是服务端的处理页面'zipcode.PHP
$dbuser = 'root';
$dbpass = '111111';
$cn = mysql_connect("localhost", $dbuser, $dbpass);
$db = mysql_select_db("ajax");
$sql = "select city, state from zipcodes where zipcode = " . $_REQUEST['zip'];
$rs = mysql_query($sql);
$row = mysql_fetch_array($rs);
echo $row['city'] . "|" . $row['state'];
mysql_close($cn);
?>
当客户输入一个POSTCODE后,zipcode.PHP就接收到它,然后进行从数据表中取出对应的资料,再按一定的格式返回给客户端(此处是以 | 分隔)。最后客户端接收返回的资料,显示在页面上。
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById("city").value = update[0];
document.getElementById("state").value = update[1];

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319751.htmlTechArticlescript function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro...