gpt4 book ai didi

javascript - javascript 中的 httprequest 和二进制数据

转载 作者:太空狗 更新时间:2023-10-29 16:43:00 26 4
gpt4 key购买 nike

在多次尝试读取 httprequest 的响应后仍在努力,该响应是表示 jpg 图像的二进制数据流。

编辑:整个事情

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

任何想法出了什么问题或我可以尝试什么?

最佳答案

我做了 this example在客户端读取二进制 JPEG 并解析 EXIF 数据。它使用 BinFileReader.js这使得跨浏览器处理二进制数据变得非常容易。 Here is the whole thing in a zip file ,包括一个基于节点的网络服务器(使用 node server.js 运行)我包括了一个 web-worker example , 还有。

如果你只是用二进制流制作图像,为什么不直接添加 <img src="blah" />到你的 DOM?

$('body').append('<img src="' + URL + '"/>');

关于javascript - javascript 中的 httprequest 和二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10737926/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com