2012-07-09 28 views
0

這是背景。我試圖從以下代碼中使用php,ajax和jquery的mysql服務器中檢索unicode字符。如何使用jquery ajax顯示unicode字符?

$.post("test.php",{tableName: A_table}, function(data) 
    { 
     $.each($(data), function(key, value) 
     { 
      display data into an UL List and not display weird unicode characters, like   00101C 
     } 

    }); 

根據上面的代碼,我該如何獲取unicode字符才能顯示。

回答

0

你應該強迫你迴應的charset標題爲UTF-8(或其他合適的字符集爲您的需求),或者你可以在服務器端所有的Unicode字符先前轉換與mb_convert_encoding

例如(從手冊頁取)

<?php 
$text = "A strange string to pass, maybe with some ø, æ, å characters."; 

foreach(mb_list_encodings() as $chr){ 
    echo mb_convert_encoding($text, 'UTF-8', $chr)." : ".$chr."<br>"; 
} 
?>