Web应用程序显示“E”作为 [英] Web application display 'é' as �

查看:88
本文介绍了Web应用程序显示“E”作为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Web应用程序,code在PHP,HTML,JAVASCRIPT,AJAX,JQuery的。

I am working on a web application that is code in PHP, HTML, Javascript, AJAX, JQuery.

它与一个MySQL数据库。

It is linked to a MySQL DataBase.

下面的问题:

大多数在数​​据库中的文字是在法国和像'E','U','A'是showned在我的页面,一些特殊字符

Most of the text in the DataBase is in french and some special character like 'é', 'ù', 'à' are showned on my page as �.

N.B。为了让更多的信息,如果我输入'E'一种形式,我的应用程序在我的数据库'A',如果我插入我的数据库中的'E'是显示在我的应用程序的写了。

N.B. To give more info, if i enter 'é' on a form in my application it wrote in my DataBase 'Ã' and if i insert into my DataBase an 'é' it display on my application as �.

另外的信息: 起初,'E'正确显示。但经过我有一个AJAX功能谁从数据库刷新,然后将其变成一个

Further informations: At first the 'é' displays correctly. But after I have an AJAX function who refresh it from the DataBase and THEN it turn into a �

AJAX code:

AJAX Code:

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

的code的reste仅仅是用PHP一个简单的HTML表格:<​​/ P>

The reste of the code is just a simple HTML table with 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:

Here is 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>

感谢您!

推荐答案

尝试设置的字符集为AJAX请求:

Try setting the charset for the AJAX request:

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

在这里你可以替换UTF-8与您正在使用的特定的字符集。

where you can replace "UTF-8" with the specific charset you are using.

这篇关于Web应用程序显示“E”作为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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