IE + XMLHttp + CreateObjectURL错误 [英] IE + XMLHttp + CreateObjectURL Error

查看:136
本文介绍了IE + XMLHttp + CreateObjectURL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试下载并在iFrame中显示远程文件的内容,并且除IE之外的所有浏览器都成功(我正在尝试使用IE 10)。
我使用了XMLHttpRequest,Blob,CreateOBjectUrl API来完成这个过程。

I am trying to download and show the contents of a remote file inside an iFrame , and succeeded in all browsers except for IE(i am trying with IE 10). I have used XMLHttpRequest,Blob,CreateOBjectUrl APIs to complete the process.

在IE中,我无法查看iFrame中的文件内容,也没有控制台上也出现了特殊的错误消息。

In IE i am not able to view the file content inside the iFrame and also no particular error messages appeared on console as well.

我已将我的代码粘贴在此主题的底部,并按步骤解释如下

I had pasted my code at the bottom of this thread , and a step by step explanation as below


  1. 获取下载文件网址&相应的mime
    类型(在所有broswers中都非常好)。

  2. 调用XMLHttp请求,
    Http GET异步调用,响应类型为'arraybuffer'(在所有浏览器中完美
    )完成XMLHttpGet以下3个步骤是
    执行。

  3. 使用正确的mimetype创建一个blob;(在所有其他浏览器中都非常好,通过使用MSSaveOrOpenBlob方法在IE中下载它来专门验证blob)。
    4.InOrder将blob内容绑定到iFrame,使用createObjectURL创建blob url(在所有浏览器中都非常好,但在IE中我们没有得到完美的URL)。

  4. 最后将网址与iFrame绑定以供显示。

  1. Getting the download document url & corresponding mime type(Perfectly fine in all broswers).
  2. Invoking XMLHttp Request , a Http GET Async call ,as response type as 'arraybuffer' (Perfectly fine in all browsers) Upon completing the XMLHttpGet below 3 steps are executing.
  3. Creating a blob using the proper mimetype ;(Perfectly fine in all other browsers, specially verified the blob by downloading it in IE using MSSaveOrOpenBlob method). 4.InOrder to bind the blob contents to the iFrame , create the blob url using "createObjectURL" (Perfectly fine in all browsers , but in IE we are not getting a perfect URL).
  4. Finally binding the URL with the iFrame for display.

以下代码段。

// Getting the document url and mime type ( Which is perfectly fine )

  var downloadUrl=finalServerURL + "DocumentService.svc/GetItemBinary?id=" + itemId + "&version=" + version;

var mimeTypeForDownload = responseStore.mimeTypes[currentlySelectedObject.fileExtension];



  window.URL = window.URL || window.webkitURL;

//Defining the XML Http Process

                var xhr = new XMLHttpRequest();

                xhr.open('GET', downloadUrl, true);

                xhr.responseType = 'arraybuffer'; //Reading as array buffer .

                xhr.onload = function (e) {

                    var mimeType = mimeTypeForDownload;

                    var blob = new Blob([xhr.response], { type: mimeType });

                    // Perfect blob, we are able to download it in both IE and non-IE browsers



                    //This below url  from createObjectURL,

                    //Working perfectly fine in all non-IE browsers, but nothing happening in IE

                    var url = window.URL.createObjectURL(blob);



                document.getElementById(documentContentiFrameId).setAttribute("src", url);



                };

                xhr.send;

如果你得到任何相关信息,请告诉我,这将非常有帮助。

Please let me if you get any information on this , would be really helpful.

推荐答案

我开始知道在IE中无法为你的blob条目获取正确的URL,我的尝试都没有成功。
我的替代解决方案,
1)转到pdf.js,一个开源的javascript库,它允许渲染pdf二进制文件和等效的pdf blob。
2)利用开放的PDF库编写自己的观众,这将耗费大量时间,并且需要更多的学习努力。

I came to know that its not possible in IE to get a proper URL for your blob entries , none of my attempts are get succeeded. My alternative solutions, 1)go for pdf.js , an open source javascript library , which allows to render pdf binaries and equivalent pdf blobs. 2)Write your own viewers by utilizing the open PDF libraries , which will be time consuming , and more learning efforts involved.

谢谢,
毗湿奴

Thanks, Vishnu

这篇关于IE + XMLHttp + CreateObjectURL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆