var ajax = null;
function getCity(province_id){
ajax = createAjax();
ajax.onreadystatechange=function(){
if(ajax.readyState == 4){
if(ajax.status == 200){
var cities = ajax.responseXML.getElementsByTagName("city");
$('city').length = 0;
var myoption = document.createElement("option");
myoption.value = "";
myoption.innerText = "--请选择城市--";
$('city').appendChild(myoption);
for(var i=0;i
var city_id = cities[i].childNodes[0].childNodes[0].nodeValue;
var city_name = cities[i].childNodes[1].childNodes[0].nodeValue;
var myoption = document.createElement("option");
myoption.value = city_id;
myoption.innerText = city_name;
$('city').appendChild(myoption);
}
}
}
}
ajax.open("post","selectPro.php",true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send("province_id="+province_id);
这里是AJAX页面的代码
PHP页面代码如下:
if(!empty($_POST['province_id'])){
$province_id = $_POST['province_id'];
$sql = "select * from shi where yid = $province_id";
$query = mysql_query($sql);
$info = "";
echo $info;
}
我就是搞不清楚为什么要加select这个XML节点,才能返回AJAX的值?拿掉就返回不了值了。这里的