3.0 beta 2

[HTTP]Change charset in Ajax request ('UTF-8' -> 'ISO-8859-1' )

Hi everyone,

I need to change the defult encoding charset of HTTPxml object form "UTF-8" to "ISO-8859-1".

In other words, I have a textarea filled by users, and then an ajax request that communicates with "the backend". (In the backend the encoding charset is "ISO-8859-1" and I can't change it.) Actually all "strange" characters, such as "è", "é" etc., arrives modified and I'm trying to force the HTTPxml to use the same character encoding used in the backend.

Any suggest?

Thank you!

Ps. I'm sorry for my very-bad english :-P
Francesco Pezzato
February 21,
Try the javascript escape() function before sending the content with the AJAX request. It should work...
Jose Luis (Spain)
February 21,
Thanks for your help!

However the "escape" function doesn't solve my problem: in fact I have no control in the backend, so I can't do something like an "unescape" function to convert back characters converted to esadecimal values ...

Francesco Pezzato (Italy)
February 22,
And another little thing:

I'm trying to use the "setRequestHeader()" property of HTTPxml in this way:
var areq = new Active.HTTP.Request;
 areq.setRequestHeader("Content-Type","application/x-javascript; charset:ISO-8859-1");

but nothing changes...

Francesco Pezzato (Italy)
February 22,
We have been working on that for quite a while and did not come up with a solution. javascript uses UTF-8 as internal encoding and it seems as if there is no way to come around that.

change your backend. ;-)

February 22,
If you don´t have control in your backend I have no idea how you can do it... In my case I use escape() in the client side and URLDecoder.decode(requestParameter, "ISO-8859-1") in the backend (Java).

Sorry :(
Jose Luis (Spain)
February 23,
Thanks for your answers!

This isn't exactly what I've planned, but after hours and hours of useless tests, I've obliged the developer of backend to use the decode function...

and now it works perfectly! (Thank you Jose Luis!)

Francesco Pezzato (Italy)
February 23,
XMLHTTPREQUEST() use UNICODE CHARSET. So, change your webserver default charset to UTF-8. Unicode is here. Unicode is the future. Drop ISO-8859-1 as soon as possible.
November 18,
there's a way...
you are able to override the mimetype by creating an XMLHttpRequest.

if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml; charset=iso-8859-1');

April 6,

I wasted hours for my demo at because of these special characters.


Customer Management is now UTF-8 based and also displays special characters.

Trick was setCharacterEncoding,
final void sendAjaxResponse(String js, HttpServletResponse response) {
    try {
        response.getWriter().write("this._data = " + js + ";");
    } catch (Exception e) {
        // ignore exception here

Hope it will help someone using J2EE.

Sudhaker Raj (http://thej2ee.com)
April 6,
if (http_request.overrideMimeType) { 
            http_request.overrideMimeType('text/xml; charset=iso-8859-1'); 

this code is working for mozilla but not for IE
June 28,

This topic is archived.

See also:

Back to support forum


Version 2

Looking for AW 2.6 ?
The old site is here.