使用FireFox的UTF-16字符编码问题 [英] UTF-16 character encoding issue with FireFox
问题描述
我遇到了UTF-16编码的XML和Firefox的问题,我似乎无法解决。
我正在使用TFS11 Web访问API来创建自定义工作项目控件。这个应该是不相关的,但是可以说我不能乱用任何web服务器设置或者应用程序发送数据的方式。
一般工作流程是控制下拉附件文件,将其解析为XML,然后使用XML来为最终用户呈现数据。这一切都在IE8,IE9和Chrome完美的作品。但是,在FireFox 11中,并没有。
下面是一段代码,演示了如何抓取我的XML并解析它:
$。ajax({
url:uri,
async:true,
dataType:text,
complete:function(xhr,status) {
if(xhr.responseText!= null){
data = null;
if(window.DOMParser){
parser = new DOMParser();
var responseText = xhr.responseText;
data = parser.parseFromString(responseText,text / xml);
}
}
}
});
问题在于 xhr.responseText
。在FireFox中,它包含 <? x m l v e r s i o n = 1 . 0 e n c o d i n g = u t f - 1 6 >
(依此类推)。
$ b 前两个字符是FF FE。我已经读过,我知道这是字节顺序标记。我不明白的是为什么我看到这个,而不是正确的编码文本。
这是我的请求响应头:
HTTP / 1.1 200 OK
Cache-Control:private
Content-Type:application / octet- stream
服务器:Microsoft-IIS / 7.5
X-TFS-ProcessId:0bc401d6-0b5d-47a4-85b8-114344957d22
X-AspNetMvc-Version:3.0
内容处理:附件; filename = d187d991-550a-4f49-b379-3bea7f9518c8.xml
X-AspNet-Version:4.0.30319
Persistent-Auth:true
X-Powered-By:ASP.NET
X-Content-Type-Options:nosniff
X-FRAME-OPTIONS:SAMEORIGIN
日期:2012年3月15日星期四17:15:00 GMT
内容长度:7520
是否有解决方法?
在你的回应中发送正确的编码?它看起来像Firefox没有在您的数据中查看BOM,所以没有意识到您的数据是UTF-16而不是UTF-8 ....
I'm encountering an issue with UTF-16 encoded XML and Firefox that I can't seem to resolve.
I'm working with the TFS11 web access API in order to create a custom work item control. That should be irrelevant, but suffice it to say that I'm not at liberty to mess with any of the web server settings or the way in which the application sends the data.
The general workflow is that the control pulls down an attachment file, parses it as XML, and then works with the XML in order to render data for the end-user. This all works perfectly in IE8, IE9, and Chrome. However, in FireFox 11, it does not.
Here's a snippet of code that demonstrates how I'm grabbing my XML and parsing it:
$.ajax({
url: uri,
async: true,
dataType: "text",
complete: function (xhr, status) {
if (xhr.responseText != null) {
data = null;
if (window.DOMParser) {
parser = new DOMParser();
var responseText = xhr.responseText;
data = parser.parseFromString(responseText, "text/xml");
}
}
}
});
The problem is the contents of xhr.responseText
. In FireFox, it contains ��<?�x�m�l� �v�e�r�s�i�o�n�=�"�1�.�0�"� �e�n�c�o�d�i�n�g�=�"�u�t�f�-�1�6�"�?�>
(and so on).
The first two characters are FF FE. I've read up on it, and I know that this is the Byte Order Marker. What I don't understand is why I'm seeing this instead of correctly encoded text.
Here are my response headers from the request:
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/octet-stream
Server: Microsoft-IIS/7.5
X-TFS-ProcessId: 0bc401d6-0b5d-47a4-85b8-114344957d22
X-AspNetMvc-Version: 3.0
Content-Disposition: attachment; filename=d187d991-550a-4f49-b379-3bea7f9518c8.xml
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
X-Content-Type-Options: nosniff
X-FRAME-OPTIONS: SAMEORIGIN
Date: Thu, 15 Mar 2012 17:15:00 GMT
Content-Length: 7520
Is there a workaround for this?
Send the right encoding in your response? It looks like Firefox is not looking at the BOM in your data, so doesn't realize your data is UTF-16 and not UTF-8....
这篇关于使用FireFox的UTF-16字符编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!