Convert ISO-8859-1 to UTF-8

I am sending an HTTP request through jQuery ajax.

But the server, to which I do not have access, returns ISO-8859-1, and I am my UTF-8 page.

How to convert characters to read?

For without conversion, something like: it rio appears

@Edit: I tried changing the ajax request encoding using:

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

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

@Solution: I found a solution on: https://stackoverflow.com/a/3168/

+3
javascript jquery utf-8 iso-8859-1
Mar 23 '14 at 5:06
source share
1 answer

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

in your case you can just use:

 utfstring = unescape(encodeURIComponent(ajaxreturn)); 

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

 fixedstring = decodeURIComponent(escape(ajaxreturn)); 

It can also help if you publish the output of the "encode" functions - this way you can determine what happens:

 encodeURIComponent(ajaxreturn) vs. escape(ajaxreturn) 

If none of these work, I think you should convert your entire page to iso-8859-1:

  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
+5
Mar 23 '14 at 17:59
source share



All Articles