这是我的代码。
var xhr = new XMLHttpRequest();
xhr.open('GET',window.location.href, true);
xhr.responseType = "arraybuffer";
xhr.onload = function(event) {
debugger;
console.log(" coverting array buffer to string ");
alert(String.fromCharCode.apply(null, new Uint8Array(this.response)));
};
xhr.send();
该请求是针对大小约为 3 MB 的 PDF URL 发出的。我读过几个线程,它们都出现了同样的错误,超出了最大调用堆栈大小,告诉我必须进行一些递归调用,但我在这里没有看到任何递归调用。谁能帮忙?
最佳答案
我遇到了同样的问题,最后我使用了this code :
function _arrayBufferToBase64( buffer ) {
var binary = '';
var bytes = new Uint8Array( buffer );
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
}
return window.btoa( binary );
}
关于javascript - 将数组缓冲区转换为字符串 : Maximum call stack size exceeded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38432611/