电脑安全

您当前的位置:主页 > 电脑安全 >

php+ajax无刷新实现省、地、市三级联动-网络编程

来源:[db:来源]标题:   仿宋    编辑:电脑技术全能网 时间:2019-09-22 06:21

原标题:php+ajax无刷新实现省、地、市三级联动-网络编程
   <html><head><metahttp-equiv="Content-Type"c/><scripttype="text/javascript">varxmlHttp;varrequestType="";functioncreateXMLHttpRequest(){if(window.ActiveXObject){xmlHttp=newActiveXObject("Microsoft.XMLHTTP");}elseif(window.XMLHttpRequest){xmlHttp=newXMLHttpRequest();}}functionqueryCity(citycode){createXMLHttpRequest();type="city";varurl="data.php?provincecode="+citycode;xmlHttp.open("GET",url,true);xmlHttp.onreadystatechange=handleStateChange;xmlHttp.send(null);}functionqueryArea(citycode){createXMLHttpRequest();type="area";varurl="data.php?citycode="+citycode;xmlHttp.open("GET",url,true);xmlHttp.onreadystatechange=handleStateChange;xmlHttp.send(null);}functionhandleStateChange(){if(xmlHttp.readystate==4){if(xmlHttp.status==200){if(type=="city"){showcity();}elseif(type="area"){showarea();}}}}functionshowcity(){document.getElementById("city").innerHTML=xmlHttp.responseText;document.getElementById("area").innerHTML="";}functionshowarea(){document.getElementById("area").innerHTML=xmlHttp.responseText;}</script></head><body><?$conn=mysql_connect("localhost","root","2328725");mysql_select_db("novel");mysql_query("setnames'utf8'");$sql="select*fromprovince";$result=mysql_query($sql);echo"<fromid='form1'>/n";echo"<selectid='province'onchange='queryCity(this.options[this.selectedIndex].value)'>/n";echo"<optionvalue='-1'selected>请抉择省分</option>/n";while($row=mysql_fetch_row($result)){echo"<optionvalue='$row[1]'>$row[2]</option>/n";}echo"</select>/n";echo"<spanid='city'></span>/n";echo"<spanid='area'></span>/n";echo"</form>/n";?></body></html>

上一篇:php foreach用法-网络编程

下一篇:没有了