:: Forum >> Version 1 >>

[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
Tuesday, February 21, 2006
Try the javascript escape() function before sending the content with the AJAX request. It should work...
Jose Luis (Spain)
Tuesday, February 21, 2006
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)
Wednesday, February 22, 2006
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...





Hi!
Francesco Pezzato (Italy)
Wednesday, February 22, 2006
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. ;-)

Tobias
Wednesday, February 22, 2006
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)
Thursday, February 23, 2006
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)
Thursday, February 23, 2006
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.
bla
Saturday, November 18, 2006
hi
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');
}
 
osfriese
Friday, April 6, 2007

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

http://thej2ee.com/tutorial.item.2/awgrid-gpl-row-editing-using-popup.html

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

Trick was setCharacterEncoding,
final void sendAjaxResponse(String jsHttpServletResponse response) {
    
try {
        
response.setCharacterEncoding("UTF-8");
        
response.getWriter().write("this._data = " js ";");
        
response.flushBuffer();
    } 
catch (Exception e) {
        
// ignore exception here
    
}
}
 
Hope it will help someone using J2EE.

Cheers,
Sudhaker Raj (http://thej2ee.com)
Friday, April 6, 2007
if (http_request.overrideMimeType) { 
            
http_request.overrideMimeType('text/xml; charset=iso-8859-1'); 
}  
this code is working for mozilla but not for IE
carlos
Thursday, June 28, 2007



This topic is archived.

Back to support forum

Forum search