<!doctype html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="js/common.js"></script>
  <script>
function loadProvince(){
//获取xhr
var xhr=createXhr();
//创建请求
xhr.open("get","php/province2.php",true);
//设置回调函数
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var resText=JSON.parse(xhr.responseText);
console.log(resText);
                var html="";
for(var i=0;i<resText.length;i++){
html+="<option value=";
html+=i;
html+=">";
html+=resText[i];
html+="</option>";
}
console.log(html);
$("selProvince").innerHTML=html;
}
}
//发送请求
xhr.send(null);
}
  </script>
  <script>
function loadCity(){
//获取xhr
var xhr=createXhr();
//创建请求
var pid=$("selProvince").value;
var url="php/province3.php?pid="+pid;
xhr.open("get","php/province3.php?pid="+pid,true);
//设置回调函数
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
console.log(xhr.responseText);//为什么xhr.responseText()接收不到json字符串???我哪里有问题
var opts=JSON.parse(xhr.responseText);
var html="";
for(var i=0;i<opts.length;i++){
html+="<option value=";
html+=i;
html+=">";
html+=opts[i];
html+="</option>";
}
$("selCity").innerHTML=html;
}
}
//发送请求
xhr.send(null);
}
  </script>
  <script>
function onloadPrev(){
loadProvince();
loadCity();
}
  </script>
 </head>
 <body onload="onloadPrev()">
<select id="selProvince"></select> 
<select id="selCity"></select>
 </body>
</html><?php
    header("Content-Type:application/json");
$province=["黑龙江","吉林","辽宁"];
echo json_encode($province);
?>
<?php
header("Content-Type:application/json");
$city=[
["黑河","哈尔滨","五常市"],
["长春","四平市","松原市"],
["沈阳","大连市","抚顺市"]
];
$value=$_REQUEST["pid"];
//var_dump($city);
echo json_encode($city[$value]);
?>