javascript - 无法在 IE 11 中通过 FileReader 读取 SQL blob

标签 javascript php sql ajax

我正在通过 AJAX 从 SQL 数据库读取一个 blob,下面的代码在 FireFox、Edge 和 Chrome 中运行良好,但我在调试器中收到 xmlhttp.responseType 行的错误“无效状态错误” = "blob"; 在 IE11 中。我已经尝试了 xmlhttp.responseType 的各种组合,但无法让它在 IE11 中工作。例如,如果我只是注释掉 xmlhttp.responseType = "blob";,我会在 xmlhttp.responseType = "blob"; 行中获得“类型不匹配错误”。并想知道是否有人可以帮助我解决这个问题。这是我的 html 文件中用于发出 ajax 请求的代码:

if (window.XMLHttpRequest) {
           // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
        } else {
           // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }



        xmlhttp.responseType = "blob";



        xmlhttp.onreadystatechange = function()
        {
            if (this.readyState == 4 && this.status == 200)
            {
               theResponse=this.response;
               theBlobSize=theResponse.size;
               reader = new FileReader();
               reader.addEventListener("loadend", function()
               {

                   // get data from blob here 

                });
                reader.readAsArrayBuffer(theResponse);

               }
            };
            xmlhttp.open("POST","getImagAlgebraicBlob.php",true);
            xmlhttp.send();
        }

这里是 php 文件“getImagAlgebraicBlob.php”被调用以使用 PDO 读取 blob,非常简单,并且在其他浏览器中完美运行:

<?php

include 'algebraicFunctionBlobClass.php';

$blobObj = new algebraicFunctionBlob();

$a = $blobObj->selectImagBlob(132);

echo $a['imagWebGLData'];
?>

谢谢

最佳答案

IE6/5 早已不复存在,因此您无需对此进行特殊处理

如果直接将responseType设置为arraybuffer,则不必使用FileReader...

var xhr = new XMLHttpRequest

xhr.onload = function() {
  var buffer = this.response
  var size = buffer.byteLength

  // construct the arraybuffer as a blob if you ever need it
  // var blob = new Blob([buffer])
}

xhr.open('POST', 'getImagAlgebraicBlob.php')
xhr.responseType = 'arraybuffer'
xhr.send()

关于javascript - 无法在 IE 11 中通过 FileReader 读取 SQL blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40385010/

相关文章:

javascript - 如何增加垂直高度并在 Bootstrap 中的 div 滚动中的内容之间添加空间

javascript - 分配元素特定的 bool 值以确定元素是否先前已被单击 - 当前代码毯更新所有元素

javascript - Web Worker/Canvas 内存泄漏

PHP 子类不调用其父类构造

SQLite 每小时订单数

mysql - 在 SQL 表中查询

javascript - 在 Meteor 中,FS.Store.GridFS TransformWrite 函数中未定义 Images 集合

php - 建筑工地..定制库存系统..购物车推荐?

php - 如果是 index.php,则显示 "this",如果不是,则显示 "this"

sql - OrientDB 如何在一个查询中获取顶点及其边的结果集