<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[ajax+php无刷新二级联动下拉菜单(省市联动)源码]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[代码编程]]></category>
<pubDate>Mon, 02 Oct 2006 02:40:06 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	ajax.js<br/><br/>/**<br/> * ajax无刷新二级联动下拉菜单(省市联动)<br/> *<br/> * @author &nbsp; &nbsp; &nbsp;arcow &lt;arcow@126.com&gt;<br/> * @version &nbsp; &nbsp; 1.0<br/> * @lastupdate &nbsp;2005-12-29<br/> *<br/> */<br/>var http_request = false;<br/> function send_request(url,method) {//初始化、指定处理函数、发送请求的函数<br/> &nbsp;http_request = false;<br/> &nbsp;//开始初始化XMLHttpRequest对象<br/> &nbsp;if(window.XMLHttpRequest) { //Mozilla 浏览器<br/> &nbsp; http_request = new XMLHttpRequest();<br/> &nbsp; if (http_request.overrideMimeType) {//设置MiME类别<br/> &nbsp; &nbsp;http_request.overrideMimeType(&#039;text/xml&#039;);<br/> &nbsp; }<br/> &nbsp;}<br/> &nbsp;else if (window.ActiveXObject) { // IE浏览器<br/> &nbsp; try {<br/> &nbsp; &nbsp;http_request = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);<br/> &nbsp; } catch (e) {<br/> &nbsp; &nbsp;try {<br/> &nbsp; &nbsp; http_request = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);<br/> &nbsp; &nbsp;} catch (e) {}<br/> &nbsp; }<br/> &nbsp;}<br/> &nbsp;if (!http_request) { // 异常，创建对象实例失败<br/> &nbsp; window.alert(&quot;不能创建XMLHttpRequest对象实例.&quot;);<br/> &nbsp; return false;<br/> &nbsp;}<br/> &nbsp;switch(method){<br/> &nbsp;case 1: http_request.onreadystatechange = processRequest1;break;//选择操作函数<br/> &nbsp;case 2: http_request.onreadystatechange = processRequest2;break;<br/> &nbsp;case 3: http_request.onreadystatechange = processRequest3;break;<br/> &nbsp;}<br/> &nbsp;// 确定发送请求的方式和URL以及是否同步执行下段代码<br/> &nbsp;http_request.open(&quot;GET&quot;, url, true);<br/> &nbsp;http_request.send(null);<br/> }<br/> // 处理返回信息的函数<br/> &nbsp; &nbsp;function processRequest1() {//操作函数1,调入省<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (http_request.readyState == 4) { // 判断对象状态<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (http_request.status == 200) { // 信息已经成功返回，开始处理信息<br/> &nbsp;document.getElementById(&quot;statusTxt&quot;).innerHTML=&quot;&quot;;<br/> &nbsp;addOptionGroup(&quot;province&quot;,http_request.responseText);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else { //页面不正常<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(&quot;您所请求的页面有异常。&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}else {//只要未读取完成<br/> &nbsp; &nbsp;document.getElementById(&quot;statusTxt&quot;).innerHTML=&quot;正则读取数据中……&quot;;<br/> &nbsp;}<br/> &nbsp; &nbsp;}<br/> <br/> function processRequest2() {//操作函数2,调入市<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (http_request.readyState == 4) { // 判断对象状态<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (http_request.status == 200) { // 信息已经成功返回，开始处理信息<br/> &nbsp;document.getElementById(&quot;statusTxt&quot;).innerHTML=&quot;&quot;;<br/> &nbsp;addOptionGroup(&quot;city&quot;,http_request.responseText);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else { //页面不正常<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(&quot;您所请求的页面有异常。&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}else {//只要未读取完成<br/> &nbsp; &nbsp;document.getElementById(&quot;statusTxt&quot;).innerHTML=&quot;正则读取数据中……&quot;;<br/> &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;function processRequest3() {//操作函数3,输入省市<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (http_request.readyState == 4) { // 判断对象状态<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (http_request.status == 200) { // 信息已经成功返回，开始处理信息<br/> &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById(&quot;statusTxt&quot;).innerHTML=&quot;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById(&quot;district&quot;).value=http_request.responseText;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else { //页面不正常<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(&quot;您所请求的页面有异常。&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;}else {//只要未读取完成<br/> &nbsp; &nbsp;document.getElementById(&quot;statusTxt&quot;).innerHTML=&quot;正则读取数据中……&quot;;<br/> &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> function loadProvince() {//载入省<br/> &nbsp;send_request(&quot;select.server.php?action=province&quot;,1);//服务端处理程序,操作函数<br/> }<br/> <br/> function loadCity() {//载入市<br/> &nbsp; &nbsp; document.getElementById(&quot;district&quot;).value=&quot;&quot;;//清空文本框<br/> &nbsp; &nbsp; send_request(&quot;select.server.php?action=city&amp;id=&quot;+document.getElementById(&quot;province&quot;).value,2);<br/> }<br/> <br/> function inputDistrict() {//向文本框输入选定的省市<br/> &nbsp; &nbsp; send_request(&quot;select.server.php?action=district&amp;id=&quot;+document.getElementById(&quot;province&quot;).value+&quot;&amp;id1=&quot;+document.getElementById(&quot;city&quot;).value,3);<br/> &nbsp;<br/> }<br/><br/>addOption.js<br/><br/><br/> function addOption(objSelectNow,txt,val)<br/> {<br/> &nbsp;/// 使用W3C标准语法为SELECT添加Option<br/> &nbsp;var objOption = document.createElement(&quot;OPTION&quot;);<br/> &nbsp;objOption.text= txt;<br/> &nbsp;objOption.value=val;<br/> &nbsp;objSelectNow.options.add(objOption);<br/> }<br/> function addOptionGroup(selectId,optGroupString)<br/> {<br/> &nbsp;var optGroup = optGroupString.split(&quot;,&quot;);<br/><br/> &nbsp;var objSelect = document.getElementsByTagName(&quot;SELECT&quot;);<br/> &nbsp;var objSelectNow = objSelect[selectId];<br/> &nbsp;objSelectNow.length = 1;<br/> &nbsp; &nbsp; /// 成组添加Options<br/> &nbsp;for (i=1; i&lt;optGroup.length; i++)<br/> &nbsp;{<br/> &nbsp; addOption(objSelectNow, optGroup[i], i);<br/> &nbsp;}<br/> }<br/> <br/><br/><br/>服务端处理程序select.server.php<br/> <br/><br/>&lt;?php <br/><br/>Header(&quot;Content-type:text/html;charset=GBK&quot;);//加入头，防止乱码<br/>$referUrl=$_SERVER[&#039;HTTP_REFERER&#039;];//取得上一页面地址<br/>$referHost=$_SERVER[&#039;HTTP_HOST&#039;];//取得当前主机名<br/>$referFile=explode(&quot;/&quot;,$referUrl);//取得上一前面的主机名$referFile[2]<br/>if($referFile[2]!=$referHost)//如果上一页面与本服务端程序不在同一主机则禁止执行<br/>{<br/>exit();<br/>}<br/><br/>$aryTree = file(&quot;china.txt&quot;);//加载数据文件<br/>foreach($aryTree as $key=&gt;$value)<br/> {<br/> &nbsp; $province[$key]=explode(&quot;,&quot;,trim($value));<br/> &nbsp; $city[$key]=trim($value);<br/> }<br/> <br/>$action=$_GET[&quot;action&quot;];<br/>if($action==&quot;province&quot;&#124;&#124;$action==&quot;&quot;)<br/>{//action为province时进行以下操作，输出省<br/>$provinceStr=&quot;&quot;;<br/>for($i=0;$i&lt;count($province);++$i)<br/> {<br/> &nbsp; $provinceStr.=$province[$i][0].&quot;,&quot;;<br/> }<br/>$pattern=&quot;,$&quot;;<br/>$provinceStr=ereg_replace($pattern,&quot;&quot;,$provinceStr);<br/>echo $provinceStr;<br/>}else if($action==&quot;city&quot;){//否则为province时输出市<br/>$id=$_GET[&quot;id&quot;];<br/>echo $city[$id];<br/>}else if($action==&quot;district&quot;){//否则为district，输出省市<br/>$id=$_GET[&quot;id&quot;];<br/>$id1=$_GET[&quot;id1&quot;];<br/>echo $province[$id][0].$province[$id][$id1];<br/>}else{//否则报错<br/>echo &quot;程序出错&quot;;<br/>exit();<br/>}<br/>?&gt;<br/><br/>前台显示页面demo.htm<br/><br/><br/>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br/>&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br/>&lt;head&gt;<br/>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot; /&gt;<br/>&lt;title&gt;ajax无刷新二级联动下拉菜单(省市联动)演示V1.0&lt;/title&gt;<br/>&lt;/head&gt;<br/>&lt;script language=&quot;javascript&quot; src=&quot;js/ajax.js&quot;&gt;//加载ajax框架&lt;/script&gt;<br/>&lt;script language=&quot;javascript&quot; src=&quot;js/addOption.js&quot;&gt;//加载对select进行操作的函数&lt;/script&gt;<br/><br/>&lt;body onload=javascript:loadProvince();&gt;<br/><br/>&lt;select name=&quot;province&quot; id=&quot;province&quot; onchange=&quot;javascript:loadCity();&quot;&gt;<br/>&lt;option value=&quot;0&quot; selected=&quot;selected&quot;&gt;请选择&lt;/option&gt;<br/>&lt;/select&gt;<br/><br/>&lt;select name=&quot;city&quot; id=&quot;city&quot; onchange=&quot;javascript:inputDistrict();&quot;&gt;<br/>&lt;option value=&quot;0&quot; selected=&quot;selected&quot;&gt;请选择&lt;/option&gt;<br/>&lt;/select&gt;<br/><br/>&lt;input type=&quot;text&quot; name=&quot;district&quot; id=&quot;district&quot; readonly=&quot;&quot; /&gt;<br/>&lt;div id=statusTxt&gt;&lt;/div&gt;<br/>&lt;/body&gt;<br/>&lt;/html&gt;<br/><br/><br/>数据文件china.txt<br/><br/>请选择,请选择<br/>北京,东城,西城,崇文,宣武,朝阳,丰台,石景山,海淀,门头沟,房山,通州,顺义,昌平,大兴,平谷,怀柔,密云,延庆<br/>上海,黄浦,卢湾,徐汇,长宁,静安,普陀,闸北,虹口,杨浦,闵行,宝山,嘉定,浦东,金山,松江,青浦,南汇,奉贤,崇明<br/>天津,和平,东丽,河东,西青,河西,津南,南开,北辰,河北,武清,红挢,塘沽,汉沽,大港,宁河,静海,宝坻,蓟县<br/>重庆,万州,涪陵,渝中,大渡口,江北,沙坪坝,九龙坡,南岸,北碚,万盛,双挢,渝北,巴南,黔江,长寿,綦江,潼南,铜梁,大足,荣昌,壁山,梁平,城口,丰都,垫江,武隆,忠县,开县,云阳,奉节,巫山,巫溪,石柱,秀山,酉阳,彭水,江津,合川,永川,南川<br/>河北,石家庄,邯郸,邢台,保定,张家口,承德,廊坊,唐山,秦皇岛,沧州,衡水<br/>山西,太原,大同,阳泉,长治,晋城,朔州,吕梁,忻州,晋中,临汾,运城<br/>内蒙古,呼和浩特,包头,乌海,赤峰,呼伦贝尔盟,阿拉善盟,哲里木盟,兴安盟,乌兰察布盟,锡林郭勒盟,巴彦淖尔盟,鄂市<br/>辽宁,沈阳,大连,鞍山,抚顺,本溪,丹东,锦州,营口,阜新,辽阳,盘锦,铁岭,朝阳,葫芦岛<br/>吉林,长春,吉林,四平,辽源,通化,白山,松原,白城,延边<br/>黑龙江,哈尔滨,齐齐哈尔,牡丹江,佳木斯,大庆,绥化,鹤岗,鸡西,黑河,双鸭山,伊春,七台河,大兴安岭<br/>江苏,南京,镇江,苏州,南通,扬州,盐城,徐州,连云港,常州,无锡,宿迁,泰州,淮安<br/>浙江,杭州,宁波,温州,嘉兴,湖州,绍兴,金华,衢州,舟山,台州,丽水<br/>安徽,合肥,芜湖,蚌埠,马鞍山,淮北,铜陵,安庆,黄山,滁州,宿州,池州,淮南,巢湖,阜阳,六安,宣城,亳州<br/>福建,福州,厦门,莆田,三明,泉州,漳州,南平,龙岩,宁德<br/>江西,南昌市,景德镇,九江,鹰潭,萍乡,新馀,赣州,吉安,宜春,抚州,上饶<br/>山东,济南,青岛,淄博,枣庄,东营,烟台,潍坊,济宁,泰安,威海,日照,莱芜,临沂,德州,聊城,滨州,菏泽<br/>河南,郑州,开封,洛阳,平顶山,安阳,鹤壁,新乡,焦作,濮阳,许昌,漯河,三门峡,南阳,商丘,信阳,周口,驻马店,济源<br/>湖北,武汉,鄂州,宜昌,荆州,襄樊,黄石,荆门,黄冈,十堰,恩施,潜江,天门,仙桃,随州,咸宁,孝感<br/>湖南,长沙,常德,株洲,湘潭,衡阳,岳阳,邵阳,益阳,娄底,怀化,郴州,永州,湘西,张家界<br/>广东,广州,深圳,珠海,汕头,东莞,中山,佛山,韶关,江门,湛江,茂名,肇庆,惠州,梅州,汕尾,河源,阳江,清远,潮州,揭阳,云浮<br/>广西,南宁,柳州,桂林,梧州,北海,防城港,钦州,贵港,玉林,南宁地区,柳州地区,贺州,百色,河池<br/>海南,海口,三亚<br/>四川,成都,绵阳,德阳,自贡,攀枝花,广元,内江,乐山,南充,宜宾,广安,达川,雅安,眉山,甘孜,凉山,泸州<br/>贵州,贵阳,六<br/><br/>盘水,遵义,安顺,铜仁,黔西南,毕节,黔东南,黔南<br/>云南,昆明,大理,曲靖,玉溪,昭通,楚雄,红河,文山,思茅,西双版纳,保山,德宏,丽江,怒江,迪庆,临沧<br/>西藏,拉萨,日喀则,山南,林芝,昌都,阿里,那曲<br/>陕西,西安,宝鸡,咸阳,铜川,渭南,延安,榆林,汉中,安康,商洛<br/>甘肃,兰州,嘉峪关,金昌,白银,天水,酒泉,张掖,武威,定西,陇南,平凉,庆阳,临夏,甘南<br/>宁夏,银川,石嘴山,吴忠,固原<br/>青海,西宁,海东,海南,海北,黄南,玉树,果洛,海西<br/>新疆,乌鲁木齐,石河子,克拉玛依,伊犁,巴音郭勒,昌吉,克孜勒苏柯尔克孜,博尔塔拉,吐鲁番,哈密,喀什,和田,阿克苏<br/>香港,香港<br/>澳门,澳门<br/>台湾,台北,高雄,台中,台南,屏东,南投,云林,新竹,彰化,苗栗,嘉义,花莲,桃园,宜兰,基隆,台东,金门,马祖,澎湖<br/>其它,北美洲,南美洲,亚洲,非洲,欧洲,大洋洲<br/> <br/><br/>Tags - <a href="http://www.dzhope.com/tags/%25E4%25B8%258B%25E6%258B%2589%25E8%258F%259C%25E5%258D%2595/" rel="tag">下拉菜单</a> , <a href="http://www.dzhope.com/tags/ajax/" rel="tag">ajax</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] ajax+php无刷新二级联动下拉菜单(省市联动)源码]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>