我正在研究PHP,HTML,Javascript,AJAX,JQuery代碼的Web應用程序。Web應用程序顯示'é'爲
它被鏈接到一個MySQL數據庫。
這裏的問題是:
大部分在數據庫中的文本是在法國和一些特殊字符像「E」,「U」,「A」是showned我的頁面上。
N.B.爲了提供更多信息,如果我在我的應用程序的表單中輸入「é」,它會在我的數據庫中寫入'?',如果我在我的數據庫中插入'é',它會在我的應用程序中顯示爲 。
更多信息: 首先,'é'顯示正確。但經過我有一個AJAX功能誰刷新數據庫,然後將其變成一個
AJAX代碼:
function getXMLHttpRequest()
{
var xhr = null;
if (window.XMLHttpRequest || window.ActiveXObject)
{
if (window.ActiveXObject)
{
try
{
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else
{
xhr = new XMLHttpRequest();
}
}
else
{
alert("Votre navigateur ne supporte pas le format des données en temps réel...");
return null;
}
return xhr;
}
function request()
{
var xhr = getXMLHttpRequest();
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4 && (xhr.status == 200 || shr.status == 0))
{
readData(xhr.responseXML);
}
};
xhr.open("POST", "handlingData.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(null);
}
function readData(Data)
{
var XMLtr = Data.getElementsByTagName('tr');
for(var i = 0; i < XMLtr.length; i++)
{
var HTMLtr = document.getElementById(XMLtr[i].getAttribute('id'));
if(HTMLtr != null)
{
var XMLtd = XMLtr[i].getElementsByTagName('td');
for(var e = 0; e < XMLtd.length; e++)
{
var HTMLtd = HTMLtr.cells[e];
var HTMLtdReplace = document.createElement('td');
HTMLtdReplace.setAttribute('id', XMLtd[e].getAttribute('id'));
var InnerHTML = document.createTextNode(XMLtd[e].getAttribute("value"));
HTMLtdReplace.appendChild(InnerHTML);
HTMLtr.replaceChild(HTMLtdReplace, HTMLtd);
}
}
}
}
代碼的reste只是一個簡單的HTML表格用PHP:
<body onload="var int = self.setInterval(function(){request(readData);}, 1000);">
<div id="divWrapper">
<div id="divBgd">
<?php
if($_SESSION['User'] == null || !isset($_SESSION['User']))
{
header("Location: ../Index.php");
}
include("Header2.php");
include("Navigation.php");
include("divData.php");
echo "<div style='clear: both;'></br></div>";
echo "<div style='clear: both;'></br></div>";
?>
</div>
<div style='clear: both;'></br></div>
</div>
<div style='clear: both;'></br></div>
</body>
這裏是divData.php:
<div id="divData">
<table id="tblData" name="tblData">
<tr>
<th>Description</th>
<th>Données</th>
<th>Unitées</th>
<th>Dernière mise à jour</th>
</tr>
<?php
$cn = new cConnexion("127.0.0.1", "app_windows", "root", "jrt12345");
if($cn->DBConnexion())
{
$getData = $cn->Select("SELECT rtd_dateTime, rtd_tagId, rtd_value, tag_description, tag_units FROM realTimeData INNER JOIN tag ON tag.tag_id = realTimeData.rtd_tagId INNER JOIN plc ON plc.plc_id = tag.tag_plcId WHERE plc_id = ".$_SESSION['PLC']." AND tag_realTimeData = 1 AND tag_alarmeData = 0");
if($getData != null)
{
while($Data = $getData->fetch())
{
echo '<tr id="'.$Data['rtd_tagId'].'">';
echo '<td id="Description">'.$Data['tag_description'].'</td>';
echo '<td id="Value">'.$Data['rtd_value'].'</td>';
echo '<td id="Units">'.$Data['tag_units'].'</td>';
echo '<td id="Date">'.$Data['rtd_dateTime'].'</td>';
echo '</tr>';
}
}
}
?>
</table>
<a id="cmdRetour" href="Accueil.php">Accueil</a>
謝謝!
嗨,嘗試utf8_encode之前輸出,看看是否有幫助 –
檢查數據字段在MySQL的編碼。 – HMR
這是以前最糟糕的。我忘了告訴MySQL是Latin1(我認爲)。 – Sebastien