Ajax response encoding type changing depending on windows (UTF-8) vs unix (ISO-8859-1)

1,602 views
Skip to first unread message

husky

unread,
Jul 15, 2009, 12:00:50 PM7/15/09
to Prototype & script.aculo.us
hihi all,

i am using Ajax.request() function to call and return results on a web
page and i noticed that depending on where the server is deployed, the
encoding of the response changes.

if i am running the code locally on my windows machine, the Ajax
response encoding is UTF-8. but when deployed to a unix server, the
Ajax response encoding is ISO-8859-1.

the side-effect is that the response contains unreadable characters
because it's in the wrong encoding (should be UTF-8, but it's
ISO-8859-1)

does anyone know why this happens and how to fix this?

thanks in advance!
-h

Douglas

unread,
Jul 15, 2009, 12:23:44 PM7/15/09
to prototype-s...@googlegroups.com
Prototype has _nothing_ to do with the response code.
Your backend is sending the wrong encoding. Problably, you have not
set the correct send headers.

Are you using a PHP backend? If yes, maybe your local php.ini have
default_charset set to utf-8 and the unix one has not, by default, php
uses iso-8859-1.

Try adding this line to you response:
header('content-type:text/plain; charset=utf-8'); // of course, the
content-type you are expecting
or use [1]utf8_encode(CONTENT) before send the response.

[1] http://www.php.net/utf8-encode

~ Cheers
--
Believe nothing, no matter where you read it, or who said it, no
matter if I have said it, unless it agrees with your own reason and
your own common sense.

husky

unread,
Jul 15, 2009, 1:09:31 PM7/15/09
to Prototype & script.aculo.us
I am using WebLogic in my java web app and in my code, I'm already
setting the following:

response.setContentType("text/html; charset=UTF-8");

Also, I noticed that the correct UTF-8 is being returned (in the
response headers) when I am requesting all the other JSP pages because
I added the following to the top of every JSP:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

This problem of getting the wrong encoding type (ISO-8559-1) only
seems to happen for the Ajax.request() call, and only when on a unix
server.

Any ideas?

yuval dagan

unread,
Jul 15, 2009, 2:25:28 PM7/15/09
to prototype-s...@googlegroups.com
hi
 
I had a similar problem when I moved to apache2 on ubuntu from win 2000 server.
 try to add the line
 
AddDefaultCharset Off
 
to the site virtual directory
thats because in the new linux apache2 versions, the conf file is seperate to many files and in one of them which its name is 'cahrset' if I remember correct it sets a default charset for all sites in that apache2 server.
 
hope it helped
 
Yuval

husky

unread,
Jul 15, 2009, 3:10:25 PM7/15/09
to Prototype & script.aculo.us
That is a possibility! There is an Apache server sitting in front of
the WebLogic server.

Thank you for this, I think this should be the cause of the encoding
problem (I hope anyway)!

Best regards,
-h



On Jul 15, 2:25 pm, yuval dagan <dag...@gmail.com> wrote:
> hi
>
> I had a similar problem when I moved to apache2 on ubuntu from win 2000
> server.
>  try to add the line
>
> AddDefaultCharset Off
>
> to the site virtual directory
> thats because in the new linux apache2 versions, the conf file is seperate
> to many files and in one of them which its name is 'cahrset' if I remember
> correct it sets a default charset for all sites in that apache2 server.
>
> hope it helped
>
> Yuval
>

husky

unread,
Jul 16, 2009, 12:47:24 PM7/16/09
to Prototype & script.aculo.us
unfortunately it didn't work.

i set:

AddDefaultCharset utf-8

to the Apache conf file (under the virtualhost section) and restarted
Apache, but it is still returning ISO-8859-1 encoding when calling
Ajax.

any other ideas?

-h

On Jul 15, 2:25 pm, yuval dagan <dag...@gmail.com> wrote:
> hi
>
> I had a similar problem when I moved to apache2 on ubuntu from win 2000
> server.
>  try to add the line
>
> AddDefaultCharset Off
>
> to the site virtual directory
> thats because in the new linux apache2 versions, the conf file is seperate
> to many files and in one of them which its name is 'cahrset' if I remember
> correct it sets a default charset for all sites in that apache2 server.
>
> hope it helped
>
> Yuval
>
Reply all
Reply to author
Forward
0 new messages