html文件代码:
<html>
<head>
<title>exam</title>
<meta http-equiv="Content-Type" content="text/html" charset="utf8">
</head>
<body>
<script language="javascript">
function ajaxFunction(){
xmlHttp = '';
try{
xmlHttp=new XMLHttpRequest();
}catch(e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Miscrosoft.XMLHTTP");
}catch(e){
alert("NO AJAX");
return false;
}
}
}
return xmlHttp;
}
function callServer() {
var xmlHttp=ajaxFunction();
var city = document.getElementById("city").value;
var state = document.getElementById("state").value;
if((city == null)||(city=="")) return;
if((state == null)||(state=="")) return;
var url = "zip.php?city="+escape(city)+"&state="+escape(state);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function updatePage() {
if(xmlHttp.readyState==4){
var response=xmlHttp.responseText;
document.getElementById("zipCode").value = response;
}
}
</script>
<form action="zip.php" method="GET">
<p>City:<input type="text" name="city" id="city" size="25" onChange="callServer();"/></p>
<p>State:<input type="text" name="state" id="state" size="25" onChange="callServer();"/></p>
<p>zipCode:<input type="text" name="zipCode" id="zipCode" size="25" /></p>
</form>
</body>
</html>
php文件代码:
<?php
$city=$_GET['city'];
$state=$_GET['state'];
$output="".$city."".$state;
echo $output;
?>