6

在多次尝试读取作为 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

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

4

1 回答 1

1

我做了这个例子来在客户端读取二进制 JPEG 并解析 EXIF 数据。它使用BinFileReader.js,这使得处理二进制数据和跨浏览器变得非常容易。这是一个 zip 文件中的全部内容,包括一个基于节点的网络服务器(使用节点 server.js 运行)我还包括一个网络工作者示例

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

$('body').append('<img src="' + URL + '"/>');
于 2012-11-14T22:47:02.567 回答