微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ajax zipcode完整例子

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;	
?>

原文地址:https://www.jb51.cc/ajax/164025.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐