Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ISO-8859-1 to UTF-8 [duplicate]

I am sending a HTTP request through jQuery's ajax.

But the server, which I have no access, returns ISO-8859-1 and I my page is UTF-8.

How can I convert the characters to be readable?

For without converting appears something like: it�rio

@Edit: I've tried changing the charset of ajax requests using:

$.ajax({ contentType: ... });

And I tried to change the meta of the html to ISO-8859-1.

@Solution: I've found the solution on: https://stackoverflow.com/a/14397845/3451442

like image 867
user3451442 Avatar asked Mar 23 '14 05:03

user3451442


1 Answers

Try the trick shown in: How do I convert special UTF-8 chars to their iso-8859-1 equivalent using javascript?

in your case you could simply use:

utfstring = unescape(encodeURIComponent(ajaxreturn));

Edit: if this does not work either, try the other way round:

fixedstring = decodeURIComponent(escape(ajaxreturn));

It might also help if you post the output of the "encode" functions - this way its possible to identify what's going on:

encodeURIComponent(ajaxreturn)
        vs.
escape(ajaxreturn)

If none of these work I guess you should convert your whole page to be iso-8859-1:

 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
like image 120
Niko Avatar answered Oct 13 '22 17:10

Niko