utf-8 madness

As I wrote, I’m working on a stupid ajax (intranet) site but I’ve a lot of problem with charset encoding.

I’ve to publish, for legacy problem, all the intranet site using old ISO-8859-1 encoding BUT using the js XMLHttpRequest the data I receive is always UTF-8.

Unlucky I cannot use php to re-parse the data and to trasform to a latin encoding, anyone has a good idea to resolve this? Can I force another encoding on XMLHttpRequest?

Ok, I’m too tired to see the obvious… To resolve the problem I had simply forced the encoding via the php header function in the file I call remotely:

header(“Content-Type: application/x-javascript; charset=ISO-8859-1”);
echo $output;

now the browser show the right ÎÑTËRÑÅTÌÔñ?L strings 🙂



6 pensieri su “utf-8 madness

  1. You just saved my life… =)
    I was having the exact same problem and there was no way in hell I could get it to work properly, until I found your post and saw the obviousness of the solution!

    Thanks a lot!

  2. Thanks man – it works! I needed iso-8859-2 ;D I spent 2 hours trying to solve the problem using iconv, then JavasScript escape + unescape, and urlencode + urldecode. Ufff… But tell me what is the ‘application/x-javascript’ mime – what does it mean? Thanks!


Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...