关于ajax 接收xml乱码问题?
一个PHP文件,从数据库中取出数据,用的xml返回给ajax,GB2312编码 get方式
PHP文件顶部已经定义
header("Content-Type: text/xml;charset=GBK");
但是在IE下还是空白的,其他浏览器正常,测试返回的数据换成英文的话是没问题的
有哪位遇到过这情况的,求指点……
一下为主要代码
ajax.php
header("Content-Type: text/xml;charset=GBK");
$sheng=$_REQUEST['pro'];
$info="";
$query="select name from pre_common_district where upid=$sheng";
$result= mysql_query($query);
$info="<res>";
while($data= mysql_fetch_assoc($result)){
$info.="<city>".$data['name']."</city>";
}
$info.="</res>";
echo $info;
if(http_request){
var url="myajax.php?pro="+$('sheng').selectedIndex;
//var data="pro=";
//window.alert(data);
http_request.open("get",url,true);
//http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http_request.onreadystatechange=chuli;
http_request.send();
}
function chuli
************
var cities=http_request.responseXML.getElementsByTagName("city");
//把返回的城市动态添加到city控件
//var mycity=document.body.all.city;
//清空一下select
$('city').options.length=0;
for(var i=0;i<cities.length;i++){
$('city').options[i]=new Option(cities[i].firstChild.data,cities[i].firstChild.data);
//window.alert(cities[i].firstChild.data);
}