一个PHP文件,从数据库中取出数据,用的xml返回给ajax,GB2312编码 get方式
PHP文件顶部已经定义
header("Content-Type: text/xml;charset=GBK");
但是在IE下还是空白的,其他浏览器正常,测试返回的数据换成英文的话是没问题的
有哪位遇到过这情况的,求指点……
一下为主要代码
ajax.phpheader("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;ajax.js代码
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);
                                }
将页面改成utf-8是没问题,但是网站是GBK的,不可能为了这个问题全改,麻烦有遇到过类似问题的指点

解决方案 »

  1.   

    先发一个
    header('Content-type: text/html;charset=GBK');对于ie还必须(非ie内核的发了也没关系)
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
    header ("Pragma: no-cache");                          // HTTP/1.0
    然后才是
    header("Content-type: text/xml");
      

  2.   


    实践证明无效
    郁闷了,搞了一天了,编码问题还是没有解决,设为utf-8什么浏览器都没问题……
      

  3.   

    是不是数据库里存的是utf8,select前加mysql_query("set names gb2312") 试试看
      

  4.   


    直接来了个iconv 不管了