This is a question that never has the right answer, I searched the network many times and I could not find a solution.
xhr.open("GET", fullurl, true); if(xhr.overrideMimeType) xhr.overrideMimeType("text/html; charset=ISO-8859-1"); xhr.send(null); xhr.onreadystatechange = function(){ if(xhr.readyState == 4){ if(xhr.status == 200) alert(xhr.responseText);
It works for firefox, chrome. My answer: Text will return char as Réunion, which will appear as weird characters.
I tried many methods, such as encoding and decoding, setting a header in the response file, which does not work. I have no ideas. Please help someone.
**SOLUTION**
In your main file, make sure you set your content type and encoding.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
On the page loaded on AJAX, make sure you have it at the top.
header('Content-Type: text/html; charset=iso-8859-1');
The problem is solved, your lucky man. it is no longer needed.
if(xhr.overrideMimeType) xhr.overrideMimeType("text/html; charset=ISO-8859-1");
javascript ajax php
john
source share