簡體   English   中英

Firefox中的編碼問題

[英]Encoding problems in Firefox

使用AJAX和jQuery時,Firefox在編碼方面遇到一些大問題。 我用$.ajax()傳遞了一個字符串,在php代碼中我使用了以下函數:

header("Content-Type: text/html; charset=ISO-8859-1",true);

jQuery的:

$.ajax({
    type: 'GET',
    url: 'Filme_comparador_horarios.php',
    data: 'cartaz='+$filme_compara,
    success: function(retorno)
    {
        $('#cartaz_comp').append(retorno);
    }

PHP:

if(isset($_GET["cartaz"]))
{
    $cartaz = $_GET["cartaz"];      
    echo"
        <div class='cartaz_comp_img'><img class='cartaz_comp_imagem' src='horarios/$cartaz/filme.jpg' width='140px' height='210px'/>
        <div class='nome_comp'>$cartaz</div>
        </div>
        ";
}

我已經嘗試使用:

echo utf8_decode($cartaz);

使它可以在Firefox中正常運行,但可以在IE和Chrome中運行。

嘗試這個 :

$.ajax({
    type: 'GET',
    url: 'Filme_comparador_horarios.php',
    data: 'cartaz='+$filme_compara,
    contentType: 'text/html;charset=ISO-8859-1',
    success: function(retorno)
    {
        $('#cartaz_comp').append(retorno);
    }

您可以在PHP中嘗試使用htmlspecialchars,可以使用以下代碼,

echo htmlspecialchars("
    <div class='cartaz_comp_img'><img class='cartaz_comp_imagem' src='horarios/$cartaz/filme.jpg' width='140px' height='210px'/>
    <div class='nome_comp'>$cartaz</div>
    </div>
    ");

並在您的Ajax頁面中創建此javascript函數

function htmlspecialcharsDecode(specialChars) {
    specialChars = specialChars.replace(/&/g, "&amp;")
      .replace(/</g, "&lt;")
   .replace(/>/g, "&gt;")
  .replace(/"/g, "&quot;")
  .replace(/'/g, "&#039;");

   return specialChars;
}

在你的ajax代碼中

    success: function(retorno)
{
    $('#cartaz_comp').append(htmlspecialcharsDecode(retorno));
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM