views:

22

answers:

1

Hi,

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.

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.

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.

Many thanks for the help.

+1  A: 

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.

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

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

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

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

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');
BalusC
Im not sure where you got that info from but here is the header of my main page which is set to utf-8<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Bivakas</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />I am not currently using php...
nicky
Just noticed.. that charSet is from the co.nr domain provider... not my website :)
nicky
Then you need to jump out of the frameset. The parent page with the frame is rendering the page in ISO-8859-1.
BalusC