0

テキストボックスに文字šを表示しようとしていますが、単語内の他の文字のみが表示されています。DBからデータを取得し、json_encodeを使用して、xmlhttp.responseText経由で送信しています。alert(xmlhttp.responseText)を実行すると、文字は\ u009aとして表示されますが、UnicodeではU+0161はš用であると表示されます。たぶんこれが正しく表示されない理由ですか?私はCpanelを使用しており、DBのすべてのエンコーディングをutf8に設定しましたが、実際のページのエンコーディングをASCIIから変更することはできません。おそらくこれが文字を表示しない原因になっていますか?

メインページコード:

function loadDoc()
{
   var xmlhttp;

   // code for IE7+, Firefox, Chrome, Opera, Safari
   if (window.XMLHttpRequest)
   {
      xmlhttp=new XMLHttpRequest();
   }
   // code for IE6, IE5
   else
   {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }

   xmlhttp.onreadystatechange=function()
   {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
         alert(xmlhttp.responseText);
         var a = JSON.parse(xmlhttp.responseText);
         document.getElementById("textbox").value=a.first;
         document.getElementById("textbox2").value=a.second;
         document.getElementById("textbox3").value=a.third;
         document.getElementById("textbox4").value=a.fourth;
         document.getElementById("textbox5").value=a.fifth;
         document.getElementById("textbox6").value=a.sixth;
      }
   }

   xmlhttp.open("GET","loadTextBox.php?id=4",true);
   xmlhttp.send();
}

loadTextBox.phpコード:

<?php
header("Content-type: application/json");

---Placeholder for correct DB login info---

$result = $mysql->query(---Placeholder for correct SQL query---);

while ($row = $result->fetch_object())
{
   $queryResult[] = $row->present_tense;
}
$textboxValue = $queryResult[0];
$textboxValue2 = $queryResult[1];
$textboxValue3 = $queryResult[2];
$textboxValue4 = $queryResult[3];
$textboxValue5 = $queryResult[4];
$textboxValue6 = $queryResult[5];
echo    
json_encode(array('first'=>utf8_encode($textboxValue),'second'=>
utf8_encode($textboxValue2),'third'=>utf8_encode($textboxValue3),'fourth'=>
utf8_encode($textboxValue4),'fifth'=>utf8_encode($textboxValue5),'sixth'=>
utf8_encode($textboxValue6)));
?>
4

3 に答える 3

1

U + 009Aは、SINGLE CHARACTER INTRODUCERであり、http://www.fileformat.info/info/unicode/char/9a/index.htmで確認できるように、Caronと非常によく似ています

U + 0161は、実際のCaron Unicodeコードです(http://www.fileformat.info/info/unicode/char/161/index.htm) 。

于 2012-09-12T17:30:34.730 に答える
1

行に追加する

$mysql->query("SET CHARACTER SET 'utf8'");

loadTextBox.phpDBに接続した後、SQLクエリの前に内部でutf8_encodeで行を削除すると修正されました。

于 2012-09-16T05:03:54.073 に答える