Json使用utf8_encode编码显示未知字符

时间:2014-03-04 21:08:42

标签: php jquery json codeigniter utf-8

我正在使用无限滚动来获取codeigniter框架中数据库的最新帖子。当我从函数发送数据时,它不显示我保存在数据库中的实际印地语字符串。

我还在页面中使用了UTF-8字符编码。

这是我的代码:

 public function getNextPosts() {        
 foreach ($post as $result) {
         $postdata = '';
         $postdata .='<div class="post_content">
         इस धरा पर ही नहीं सम्पूर्ण ब्रहामंड में जो कुछ भी है यह सब मिटने वाला है जो भी पैदा हुआ है
         <a href="javascript:void(0);">अधिक पढ़ें</a></div>';

         $postdata .='<div class="post_content">
         हालाँकि जहाँ तक आत्मा की बात है उस विषय में हमें स्पष्ट हो जाना चाहिए
        <a href="javascript:void(0);">अधिक पढ़ें</a></div>';
    }
           header("Content-Type: application/json");
            $data = array('result' => $postsdata);
            $data_result = array_map('utf8_decode', $data);
            echo json_encode($data_result);
    }

jQuery的:

$('div#posts_data').infinitescroll({

    nextSelector: "div.navigation .alignleft a",
    navSelector: "div.navigation",
    contentSelector: "#posts_data",
    dataType: 'json',
    contentType: "application/json; charset=utf-8",
}, function(response) {
    var jsonData = response.result;
    $container= $("div#posts_data");
    $theCntr.append(jsonData);
});

输出:

<div class="post_content">???? ?? ????????? ?? ????? ?????? ???? ??? ???? ??? ???? ??, ?? ????? ???? ?? ???? ?? ?????? ???, ???? ???? ??????? ???? ?????, ????? ???? ?? ????? ?? ????? ???, ???? ??????????? ?? ???????????? ?? ????? ???. ????? ????? ???? ?? ???? ??......<a href="javascript:void(0);">???? ?????</a></div>

<div class="post_content">???? ?? ????????? ?? ????? ?????? ???? ??? ???? ??? ???? ??, ?? ????? ???? ?? ???? ?? ?????? ???, ???? ???? ??????? ???? ?????, ????? ???? ?? ????? ?? ????? ???, ???? ??????????? ?? ???????????? ?? ????? ???. ????? ????? ???? ?? ???? ??......<a href="javascript:void(0);">???? ?????</a></div>

0 个答案:

没有答案