这是一个问题,从来没有一个正确的答案,我有搜索很多次网和我不能找到一个解决方案。
xhr.open(GET,fullurl,真正的);
如果(xhr.overrideMimeType)xhr.overrideMimeType(text / html的;字符集= ISO-8859-1);
xhr.send(空);
xhr.onreadystatechange =功能(){
如果(xhr.readyState == 4){
如果(xhr.status == 200)
警报(xhr.responseText);
它适用于火狐,Chrome。我的responseText将返回字符像留尼旺,这将表现为奇怪的符号。
我试了很多方法,如编码和解码,设定在响应文件头不工作。我出出主意。请帮助别人。
**解决方案**
在你的主文件,请确保您设置的内容类型和字符集。
< META HTTP-当量=Content-Type的CONTENT =text / html的;字符集= ISO-8859-1/>
在您的AJAX加载网页,请确保您有这个顶部。
标题(内容类型:text / html的;字符集= ISO-8859-1);
问题解决了,你一个快乐的人。这不再需要。
如果(xhr.overrideMimeType)xhr.overrideMimeType(text / html的;字符集= ISO-8859-1);
解决方案
您不需要任何花哨像overrideMimeType。只要确保你的主要和AJAX加载网页的编码是(为preferrably UTF-8)正确。最有可能的,你都忘了 meta标签声明的编码。
This is a question that never has a proper answer, i have search the net many times and i couldnt 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 responseText will return char like Réunion, which will appear as weird symbols.
I tried many methods like encoding and decoding, setting header in response file which does not work. i'm out of ideas. Please help somebody.
**SOLUTION**
In your main file, make sure you set your content type and charset.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
In your AJAX-loaded page, make sure you have this at the top.
header('Content-Type: text/html; charset=iso-8859-1');
Problem solved, your a happy man. this is no longer needed.
if(xhr.overrideMimeType) xhr.overrideMimeType("text/html; charset=ISO-8859-1");
解决方案
You don't need anything fancy like overrideMimeType. Just make sure the encodings of your main and AJAX-loaded page are correct (preferrably UTF-8 for both). Most likely, you have forgotten the meta tag declaring the encoding.