【发布时间】:2017-03-16 01:32:39
【问题描述】:
我正在通过 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'];
?>
谢谢,
【问题讨论】:
标签: javascript php sql ajax