0

嗨,我正在使用 ajax 来获取 bd 的数据数组:

$.post
(
"lib/php/load_food.php",
{f:Base64.encode("primeros")},
function(data)
{
firsts = data;
},
"json"
);

但是在数组第一次中,具有acent 字符的字符串显示为“null”。

我正在寻找信息或帮助,但没有找到任何线索。

谢谢

4

1 回答 1

0

尝试使用 PHP rawurlencode()对 PHP 文件中的数据进行编码,并使用unescape()和 JQUERY .text()对其进行解码和正常显示:

简单的例子:


PHP文件:

<?php

$arr = array(
  "title" => rawurlencode("thís ís grêãt!")
);

echo $arr;

?>

查询:

<script type="text/javascript">

$.ajax({
  type    : "POST",
  url     : "path_to_my_file.php",
  data    : "&action=example",
  success : function(response) {
    // Parse PHP Array to Javascript Array
    var arr = $.parseJSON(response);

    // Populate the Title
    $("#my_element_id").html(unescape(arr['title'])).text();
  }
});

</script>

结果: 这太棒了!

于 2012-05-05T16:49:09.540 回答