donglian2106 2012-01-15 13:25
浏览 62

JQuery json中的西班牙语字符得到

I'm using this code to load content from the DB when the user selects an option :

<script type="text/javascript" >
    function setStore(value)
    {
        $.get("getStoreMetaInfo.php", {store_id: value, meta_type : 3},function(data){
                document.getElementById("tvaddedtext").value =  data.tv_lamp;
                document.getElementById("parttvaddedtext").value =  data.tv_part_no;
           }, "json");
    }

</script>  

in getStoreMetaInfo.php I'm doing a select from the DB and creating associative array and doing json_encode :

$meta=mysql_fetch_array($result_meta);
$result = array("tv_lamp"=>$meta['tv_lamp'],"tv_part_no"=>$meta['tv_part_no'],      
"projector_lamp"=>$meta['projector_lamp'],"projector_part_no"=>$meta['projector_part_no']);
$out = json_encode($result);
echo $out;

When the text I get from the DB is in English everything is working fine, but when I get spanish charecters for example the array $result looks like this (when using var_dump):

array(4) {
  ["tv_lamp"]=>
  string(40) "%BRAND_PROJECTOR_MODEL% TV de la L�mpara"
  ["tv_part_no"]=>
  string(32) "%BRAND_PARTNUM% TV de la L�mpara"
  ["projector_lamp"]=>
  string(44) "%BRAND_PROJECTOR_MODEL% Lamparas Proyectores"
  ["projector_part_no"]=>
  string(37) "%BRAND_PARTNUM%  Lamparas Proyectores"
}

and the json object I get looks like this (in firebug response):

{"tv_lamp":null,"tv_part_no":null,"projector_lamp":"%BRAND_PROJECTOR_MODEL% Lamparas Proyectores","projector_part_no":"%BRAND_PARTNUM%  Lamparas Proyectores"}

(the first two parameters are empty)

How can I make the json encoding work with those charecters?

By the way, in the page where I'm using the "setStore" function, I have:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

in the page head

  • 写回答

1条回答 默认 最新

  • du1913 2012-01-15 13:28
    关注

    check the encoding on your script file it should be UTF-8.

    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应