在文本框中显示š [英] Displaying š in textbox

查看:89
本文介绍了在文本框中显示š的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在文本框中显示字符š,但仅显示单词中的其他字母.我从数据库中获取数据,并使用json_encode通过xmlhttp.responseText发送数据.当执行alert(xmlhttp.responseText)时,字符以\ u009a出现,但是在Unicode中它表示U + 0161用于š.也许这就是显示不正确的原因?我正在使用Cpanel,并且已将数据库的所有编码都设置为utf8,但它不允许我将实际页面的编码从ascii更改.也许这导致字母无法显示?

I'm trying to display the character š in a textbox, but it's only displaying the other letters in the word. I'm grabbing data from a DB and, using json_encode, sending it via xmlhttp.responseText. When doing alert(xmlhttp.responseText) the character is coming up as \u009a, but in Unicode it says U+0161 is for š. Maybe this is the reason it's not displaying correctly? I'm using Cpanel, and I've set all encodings for the DB to utf8, but it won't let me change the encoding of the actual page from ascii. Maybe this is causing the letter to not be displayed?

主页代码:

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代码:

loadTextBox.php code:

<?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)));
?>

推荐答案

添加该行

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

在连接到数据库之后,在SQL查询之前的 loadTextBox.php 内部,并用 utf8_encode 删除的行对其进行了修复.

inside loadTextBox.php after connecting to the DB and before the SQL query and removing the lines with utf8_encode fixed it.

这篇关于在文本框中显示š的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆