通过这个AJAX调用得到的mch_desc是乱码,被调用的页面时getmach.php,请教一下这是哪里出现的问题啊,谢谢大家function callServer()
{
 var mch = document.getElementById("mch").value;
     var url = "getmch.php?mch=" + mch;
     xmlHttp.open('GET',url,true);
     xmlHttp.onreadystatechange = updatePage;
     xmlHttp.send(null);
}
function updatePage() 
{
    if (xmlHttp.readyState == 4) 
   {
       var response = xmlHttp.responseText;
       document.getElementById("mch_desc").value=response;
       }
}getmach.php<?php
require("../global_manage.php");if ($_GET)
  {   
  $mac=$_GET['mch'];   
  }
$sql="select mac_desc from mac_mstr where mac_code = '".$mac."'";
$res = $DB->fetch_one_array($sql);
$mac_desc=$res['mac_desc'];
echo $mac_desc;
?>

解决方案 »

  1.   

    ajax会将数据转成utf-8传送,服务端你要转一下
      

  2.   

    getmach.php
    加上一句
    header("Content-type:text/html;charset=gbk");
      

  3.   

    如果数据库是gbk编码的话,在getmach.php将内容转成utf8编码
      

  4.   

    在数据传输的时候指定编码 $.ajax({
       type: "POST",
       url: "url.php",
       data: "txt="+$('#tbox1').val(),
       success: function(msg){
         $("#Response").text(msg);
       },
       contentType:"application/x-www-form-urlencoded;charset=utf-8"
       });