ajax zipcode完整例子

前端之家收集整理的这篇文章主要介绍了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.f2er.com/ajax/164025.html

猜你在找的Ajax相关文章