加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax zipcode完整例子

发布时间:2020-12-16 02:11:23 所属栏目:百科 来源:网络整理
导读:html文件代码: html head titleexam/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=n

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读