的jQuery/AJAX设置的字符集头

问题描述:

我想设置的字符集的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

由于安全限制,这不起作用。你需要在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

\t Bivakas \t 我目前没有使用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