【发布时间】:2013-05-31 08:28:41
【问题描述】:
我正在尝试在 2 个浏览器上使用 jDataView 读取二进制文件:Chrome 和 IE9。
我在 ajax 请求之前添加了新类型 binary(使用 jQuery 1.10.0):
// Install binary dataType
jQuery.ajaxSetup({
accepts: {
binary: "text/plain; charset=x-user-defined"
},
contents: {
},
converters: {
"text binary": true // Nothing to convert
}
});
对于返回二进制流的服务器,我添加了标头:
<?php header("Content-type: text/html; charset=windows-1251"); ?>
然后是ajax请求:
$.support.cors = true;
$.ajax({
type: 'GET',
url: url,
dataType: 'binary',
mimeType: 'text/plain; charset=x-user-defined',
success: function(data) {
var view = new jDataView(data);
// ...
}
});
我正在使用方法getUint8() 来获取二进制流的一部分:
for (var l = 0; l < 8; l++) {
tx += " " + view.getUint8(l, true);
}
然后,比较tx 字符串:
0 0 0 7 12 106 212 65 (chrome) => GOOD (match the expected results)
0 0 2 94 12 106 36 65 (IE9) => 3 BAD sequences
在 Chrome 上它工作得很好,但在 IE9 上我没有相同的结果...... Chrome 使用本机 getUint8 函数,而 IE9 使用 jDataView 方法。
【问题讨论】:
-
检查两件事:1)您的
for循环在每次迭代中具有相同的l值。如果是这样,那么有问题的代码不足以找出原因; 2)当您从两个浏览器获得服务器响应时,它是相等的。如果是这样,jDataView的getUint8方法有问题; github 在问题选项卡上有类似 bugtracker 的东西,在那里报告。
标签: javascript jquery binary internet-explorer-9