Enter A United States Zipcode,Then Tab
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];