通过 AJAX 获取 BD 数据,并在数组中获取空,导致 acents

Get BD data by AJAX and get null in array cause of acents

本文关键字:获取 导致 acents 数组 AJAX BD 数据 通过      更新时间:2023-09-26

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

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

但是在数组中,具有带有 acent 字符的字符串显示为"null"。

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

谢谢

尝试使用 PHP rawurlencode() 在 PHP 文件上对数据进行编码,并使用 unescape() 和 JQUERY .text() 正常解码和呈现:

简单的例子:


PHP文件:

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

JQUERY:

<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>

结果:Thís ís grêãt!