gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 16:23:59 24 4
gpt4 key购买 nike

我正在通过 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/

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