I've been learning a lot about PHP, MySQL programming through a project I've been working on for 2 months.
I didn't know AJaX, actually. And when I find any challenge that takes time and a lot of headaches to overcome, I share the solution for the sake of saving people some time and bad moments.
My web application is in Spanish (latin american characters), and I use AJaX to show search results paginated, in order to make it simpler and faster to go through the results, sort them, etc...
And the results include words in Spanish, containing characters not supported in UTF-8, AJaX won't show those characters correctly.
And no, there's no way, so far I've researched, to change the UTF-8 character set for the XMLHttpRequest object; setRequestHeader("Content-Type", "...; charset=ISO...") won't work.
Some pages say you may encode the URI you are sending, and decode the responseText and you're all set. I assume encoding the URI applies when using GET method, or when using non-UTF-8 characters in the parameter values, but not to make the responseText UTF-8 compliant. I can't decode a responseText that was never encoded. And I wasn't able to decode the responseText when assigning it to the containing element.
So I finally found the solution on a web page, much simpler than what I would imagine: encode the string representing the HTML string at the server-side to UTF-8 before returning it.
In PHP, it's like this:
$html = "... all my html response text here ...";
or whatever way you decide to do it, the fact is, encode the response text with ut8_encode() before printing it or returning it.
Also, very important, make sure the HTML page receiving the responseText has the appropriate character encoding.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
I assume it'll work pretty much the same way on other programming languages; simply encode the response text server side before responding, and make sure the receiving page character set is utf-8.
Hope it is helpful for anyone.