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

网络编程 发布日期:2024/10/24 浏览次数:1

正在浏览:php AJAX实例根据邮编自动完成地址信息
<script>
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(zip) {
http.open('get', 'zipcode.PHP?zip='+zip);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById("city").value = update[0];
document.getElementById("state").value = update[1];
}
}
}
</script>
<h3>Enter A United States Zipcode, Then Tab</h3>
<table align="center">
<tr>
<td>Enter Zipcode:</td>
<td><input type="text" id="zipcode" name="zipcode" onBlur="sndReq(this.value);"/></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" id="city" name="city"/></td>
</tr>
<tr>
<td>State:</td>
<td><input type="text" id="state" name="state"/></td>
</tr>
</table>
以上是客户输入页面,下面是服务端的处理页面'zipcode.PHP
<?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]; 
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。