2010-07-04 175 views
1

我想設置的字符集的jQuery的電話,我使網站是一個立陶宛朋友因此有一些信件,口音等的jQuery/AJAX設置的字符集頭

據我的研究,到目前爲止( 2天值得!)顯示,我需要把它在我所爲已完成的beforeSend部分如下:

 $(document).ready(function(){ 
$('.content').load('home.html'); //by default initally load text from boo.php 
    $('#navlist a').click(function() { //start function when any link is clicked 
        $(".content").slideUp("slow"); 
        var content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file 
         $.ajax({ 
         method: "load",url: ""+content_show, 
         beforeSend: function(){ 
          XMLHttpRequest.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); 
          $("#loading").show("fast"); 
         }, //show loading just when link is clicked 
         complete: function(){ $("#loading").hide("fast");}, //stop showing loading when the process is complete 
         success: function(html){ //so, if data is retrieved, store it in html 
         $(".content").show("slow"); //animation 
         $(".content").html(html); //show the html inside .content div 
       } 
      }); //close $.ajax(
    }); //close click(
}); //close $(

我試圖將其更改爲

setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); 

其中也沒有工作,所以現在我是掖着,在我的神經末端環顧了兩天。

該網站可以在43dennis.co.nr/bivakas查看基本上它加載了一堆方形黑色問號代替具有特殊口音的字母。

非常感謝您的幫助。

+0

哦..無論使用哪種XMLHttpRequest.setRequestHeader或只是setRequestHeader函數甚至不工作...對不起忘了提, – nicky 2010-07-04 15:11:40

回答

5

由於安全限制,這不起作用。你需要在JS的運行位置的父頁面中設置字符集。 JS/jQuery將使用相同的字符集。

我檢查你的網頁的HTML代碼,我看到以下內容:

<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 

您需要通過UTF-8更換iso-8859-1,那麼你就不需要在JS/jQuery的與它的麻煩。

我檢查你的網頁的HTTP響應頭,我看到以下內容:

 
Content-Encoding: gzip 
Vary: Accept-Encoding 
Date: Sun, 04 Jul 2010 13:37:08 GMT 
Server: LiteSpeed 
Connection: close 
X-Powered-By: PHP/5.2.10 
Content-Type: text/html 
Content-Length: 600 

200 OK

Content-Type缺少charset屬性。您還需要在HTTP響應頭中設置相同的值。把這個放在你的PHP代碼之前你發送任何字符到響應主體。

header('Content-Type: text/html; charset=UTF-8'); 
+0

林不知道,你得到了這些信息,但這裏是我的主要頁面的頁眉它設置爲utf-8 <!DOCTYPE html PUBLIC「 - // W3C // DTD XHTML 1.0 Transitional // EN」 「http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional .dtd 「> \t Bivakas \t <元HT tp-equiv =「Content-Type」content =「text/html; charset = utf-8「/> 我目前沒有使用php ... – nicky 2010-07-04 15:21:18

+0

只注意到..該charSet是從co.nr域名提供商...不是我的網站:) – nicky 2010-07-04 15:25:58

+0

然後,你需要跳出框架的父頁面正在渲染ISO-8859-1中的頁面 – BalusC 2010-07-04 15:42:09