Closed Bug 528460 Opened 15 years ago Closed 14 years ago

xmlhttprequest.responseText should not been converted charset automatically

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: kexianbin, Unassigned)

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.3a1pre) Gecko/20091112 Minefield/3.7a1pre Build Identifier: Firefox 2.0- Firefox 3.6 With FF3, when I set the parameter "Accept-Charset" in the header of a request sent by XMLHttpRequest, FF3 replace it by its default value. FF2 and IE is ok with my code. My code : Code: Select all httprequest=new XMLHttpRequest(); httprequest.open('GET', "MY_URL", true); httprequest.setRequestHeader("Accept-Charset", "ISO-8859-1"); httprequest.setRequestHeader("PERSONAL_VAR", "value"); httprequest.send(null); With Firebug i see the parameter "PERSONAL_VAR" but Accept-Charset = ISO-8859-1,utf-8;q=0.7,*;q=0.7 And the current draft of the W3C XMLHttpRequest specification <http://www.w3.org/TR/XMLHttpRequest/> explicitly forbids setting the Accept header field: "If the user agent implements server-driven content-negotiation it should set Accept-Language, Accept-Encoding and Accept-Charset headers as appropriate; it must not automatically set the Accept header." Firefox should not convert my xmlhttprequest.responseText from utf-8 to charset of current page, because xmlhttprequest.responseText is in right the charset of current page, that would make nonsense characters. Reproducible: Always Steps to Reproduce: 1.index.php(save as gb2312): <? header('Content-Type', 'text/html;charset=gb2312'); echo '<div>中国人都是好样的</div>'; ?> 2.test.htm: <meta content="text/html; charset=GB2312" http-equiv="content-type"/> <script> var xhr=new XMLHttpRequest(); xhr.open('GET', 'index.php', true); xhr.overrideMimeType('text/plain; charset=x-user-defined'); xhr.onreadystatechange=function() {if (xhr.readyState==4) {alert(xhr.responseText); } }; xhr.send(''); </script> 3.the text in alert box: �й��˶��Ǻ���� Actual Results: wrong text: �й��˶��Ǻ���� Expected Results: correct text: 中国人都是好样的
Component: General → DOM: Mozilla Extensions
Product: Firefox → Core
QA Contact: general → general
In firefox 3.6.13: in test.htm, if i write: xhr.overrideMimeType('text/plain; charset=gb2312'); it works, but if i don't use overrideMimeType, firefox will take the gb2312 characters from index.php as utf-8 encoded and convert them into rubbish.
Sorry, i made a mistake in php code, it should be: header('Content-Type:text/html;charset=gb2312'); In firefox 3.6.13: if i don't set overrideMimeType, firefox can recognize gb2312 characters as gb2312 encoded. So i close the bug.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Resolution: FIXED → INVALID
Component: DOM: Mozilla Extensions → DOM
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.