0

Hi im usssing ajax to get array of data of the bd:

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

But in the array firsts, the strings who have a character with acent appear that "null".

I was looking for info or help but dont find any clue of what to do.

Thanks

4

1 に答える 1

0

PHP rawurlencode()を使用して PHP ファイルのデータをエンコードし、unescape()と JQUERY .text()を使用してデコードして通常どおりに表示してみてください。

簡単な例:


PHP ファイル:

<?php

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

echo $arr;

?>

Jクエリ:

<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 に答える