jQuery的/阿贾克斯设置字符集的头字符集、jQuery、阿贾克斯

2023-09-11 01:14:25 作者:心累

我想设置的字符集在一个jQuery致电网站,我想提出的是一个立陶宛朋友因而具有口音等一些字母

I am trying to set the charSet in a jquery call the site I am making is for a Lithuanian friend thus has some letters with accents etc.

据我的研究,到目前为止(2天价值!)的研究表明,我需要将其放置在beforeSend部分,我做了如下:

As far as my research so far (2 days worth!!!) has shown, I need to place it in the beforeSend section which I have done as follows:

     $(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 $(

我试图将其更改为

I have tried changing it to

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

这也不起作用,所以现在我被卡住,在我的神经到底有四处张望了两天。

Which also does not work, so now I am stuck and at the end of my nerves having looked around for two days.

该网站可以在43dennis.co.nr/bivakas被看作基本上,它与加载的地方有特殊的口音字母一堆方形的黑色问号。

The website can be viewed at 43dennis.co.nr/bivakas Basically it loads with a bunch of square black questions marks in place of the letters with special accents.

非常感谢您的帮助。

推荐答案

这是不会由于安全限制的工作。您需要设置字符集父页面从那里这个JS运行。该JS / jQuery将使用相同​​的字符集。

This isn't going to work due to security restrictions. You need to set the charset in the parent page from where this JS runs. The JS/jQuery will use the same charset.

我检查你的网页的HTML代码,我看到以下内容:

I checked the HTML of your webpage and I see the following:

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

您需要更换 ISO-8859-1 UTF-8 ,那么你就不需要麻烦与它在JS / jQuery的。

You need to replace iso-8859-1 by UTF-8, then you don't need to hassle with it in JS/jQuery.

我检查你的网页的HTTP响应头,我看到以下内容:

I checked the HTTP response headers of your webpage and I see the following:


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

内容类型缺少字符集属性。还需要在HTTP响应报头中设置的相同。把这个在你的PHP code,的在的你散发出的任何字符到响应主体。

The Content-Type is missing the charset attribute. You also need to set the same in the HTTP response header. Put this in your PHP code, before you emit any character into the response body.

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