Php 转义单字符介绍人,而不是实际字符
由于某种原因,\u009a被发送到xmlhttp.responseText而不是\u0161,我不知道为什么。我希望š显示在文本框中,但是,取而代之的是发送单字符介绍人。有没有办法解决这个问题 主页代码:Php 转义单字符介绍人,而不是实际字符,php,javascript,ajax,json,Php,Javascript,Ajax,Json,由于某种原因,\u009a被发送到xmlhttp.responseText而不是\u0161,我不知道为什么。我希望š显示在文本框中,但是,取而代之的是发送单字符介绍人。有没有办法解决这个问题 主页代码: function loadDoc() { var xmlhttp; // code for IE7+, Firefox, Chrome, Opera, Safari if (window.XMLHttpRequest) { xmlhttp=new XMLH
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)));
?>
在$mysql->query行中添加(“设置字符集‘utf8’”);在连接到DB之后、SQL查询之前以及使用utf8_encode删除行之前,在loadTextBox.php中修复了它。为什么同时发布JavaScript代码和php代码?当然你应该很容易确定哪一个有bug?事实上,我不知道哪一个有bug。我不是web开发专家。输入http://....../loadTextBox.php?id=4
在Web浏览器的地址栏中,查看服务器是否提供了预期的输出。我已经这样做了。这样做的结果与我的警报框在上述代码中输出的结果相同。对于所讨论的数据,它显示的\u009a与我预期的\u0161不同,并且没有显示š。我不知道这个问题是属于主页还是loadTextBox.php页面。如果loadTextBox.php
在您期望\u0161
时给了您\u009a
,那么问题在loadTextBox.php
中,所以这是一个php问题(或MySQL问题)。