最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - overrideMimeType alternative for IE - Stack Overflow

matteradmin5PV0评论

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");

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");
Share Improve this question edited Oct 3, 2010 at 19:34 john asked Oct 3, 2010 at 17:21 johnjohn 351 gold badge1 silver badge4 bronze badges 1
  • I don't think this works any more...hope I am wrong! – Brian McGinity Commented Dec 23, 2014 at 23:45
Add a ment  | 

2 Answers 2

Reset to default 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.

I can't change the encoding with the meta tag and access to the server. In IE I access the responseBody to create a responseText with the correct chars. Here is my answer :

https://stackoverflow./a/22030309/3353928

Post a comment

comment list (0)

  1. No comments so far