【发布时间】:2012-05-31 01:30:30
【问题描述】:
在多次尝试读取作为 jpg 图像的二进制数据流的 httprequest 的响应后仍然苦苦挣扎。
编辑:整件事
xmlhttp = false;
/*@cc_on@*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end@*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp = false;
}
}
xmlhttp.open("GET", theUrl, true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
var headers = xmlhttp.getAllResponseHeaders();
}
}
xmlhttp.send(null);
我使用的是 IE8,没有 HTML 5(也在 FF12 中尝试过) 所以我总是会遇到类似的错误
xhr.overrideMimeType('text\/plain; charset=x-user-defined');
或
xhr.responseType = "arraybuffer";
即使复制到变量中也不起作用
var body = xhr.response; //.responseText , .responseBody
任何想法有什么问题或我可以尝试什么?
【问题讨论】:
-
为什么?你想达到什么目的?你的服务器可以做 b64 编码吗?
-
不,它是嵌入式设备,公司不会遗憾地改变他们的界面
-
那么你应该如何在脚本端使用二进制数据呢?
-
计划是从图像数据流中创建图像
标签: javascript html xmlhttprequest binary-data responsetext