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 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘