<html>

<meta http-equiv="content-type" content="utf-8">

<head>

<script type="text/javascript"></script>

<script type="text/javascript">

var myXmlHttpRequest="";

function getXmlHttpObject()  //创建XMLHttpRequest对象

{

var xmlHttpRequest="";

if(window.ActiveXObject)

{

xmlHttpRequest=new window.ActiveXObject("Microsoft.XMLHTTP");

}

else if(window.XMLHttpRequest)

{

xmlHttpRequest=new XMLHttpRequest();

}

if(!xmlHttpRequest)

{

window.alert("未创建xmlhttprequest对象");

}

return xmlHttpRequest;

}

function cities()                   //将数据发送给服务器

{

myXmlHttpRequest=getXmlHttpObject();

myXmlHttpRequest.onreadystatechange=chuli;

if(myXmlHttpRequest)

{

      var url="provinceProc.php";

      data="province="+document.getElementById("prov").value;  

      myXmlHttpRequest.open("POST",url,true);

      myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

      myXmlHttpRequest.send(data);

}

else

{

window.alert("未获取xmlhttprequest对象");

}

}

var myXmlHttpRequest2="";

function county()

{

myXmlHttpRequest2=getXmlHttpObject();

myXmlHttpRequest2.onreadystatechange=proc;

if(myXmlHttpRequest2)

{

  var url="cityProc.php";

     data="city="+document.getElementById("s2").value;  

      myXmlHttpRequest2.open("POST",url,true);

      myXmlHttpRequest2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

      myXmlHttpRequest2.send(data);

}

else

{

window.alert("未获取xmlhttprequest对象");

}

}

function proc()

{

document.getElementById("s3").length=1;

if(myXmlHttpRequest2.readyState==4)

{

//window.alert("ok");

var res=myXmlHttpRequest2.responseXML.getElementsByTagName("county");

//alert(res[2].childNodes.length);

// alert(res.length);

for(var i=0;i<res.length;i++)

{

var countyName=res[i].childNodes[0].nodeValue;  //这里的子节点是文本节点

// window.alert(countyName);

var myoption=document.createElement("option");

myoption.innerText=countyName;

myoption.value=countyName;

document.getElementById("s3").appendChild(myoption);

}

}

}

function chuli()            //处理服务器返回的结果

{

if(myXmlHttpRequest.readyState==4)

{

var res=myXmlHttpRequest.responseXML.getElementsByTagName("city");

document.getElementById("s2").length=1;

document.getElementById("s3").length=1;

//alert(res[2].childNodes.length);

for(var i=0;i<res.length;i++)

{

var cityName=res[i].childNodes[0].nodeValue;  //这里的子节点是文本节点

// window.alert(cityName);

var myoption=document.createElement("option");

myoption.innerText=cityName;

myoption.value=cityName;

document.getElementById("s2").appendChild(myoption);

}

}

}

</script>

</head>

<body>

<select id="prov" οnchange="cities()" name="p1">

<option>省</option>

<option value="hunan">湖南省</option>

<option value="beijing">北京市</option>

</select>

<select id="s2" οnchange="county()">

<option>市</option>

</select>

<select id="s3">

<option>县</option>

</select>

</body>

</html>

<?php

header("content-type:text/xml;charset=utf-8");

header("Cache-Control:no-cache");

$province=$_POST['province'];

file_put_contents("D:\\mylog.log", $province);

if($province=="hunan")

{

$info="<?xml version='1.0' encoding='gb2312' ?><province><city>长沙</city><city>株洲</city><city>湘潭</city></province>";

}

else

{

$info="<?xml version='1.0' encoding='gb2312' ?><province><city>海淀区</city><city>朝阳区</city><city>古城区</city></province>";

}

echo $info;

?>

<?php

header("content-type:text/xml;charset=utf-8");

header("Cache-Control:no-cache");

$city=$_POST['city'];

file_put_contents("D:\\mylog.log", $province);

if($city=="长沙")

{

$info="<?xml version='1.0' encoding='utf-8' ?><city><county>东安</county><county>道县</county><county>宁远</county></city>";

}

else if($city=="株洲")

{

$info="<?xml version='1.0' encoding='utf-8' ?><city><county>株洲县</county><county>株洲县</county><county>株洲县</county></city>";

}

echo $info;

?>