问题
This is my line of code.
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();
That request is making to a pdf url which is around 3 MB in size. Read few thread with same error, telling that there must be some recursive call but I do not see any recursive call here. Any help ?
回答1:
The error is caused by a limitation in the number of function arguments. See "RangeError: Maximum call stack size exceeded" Why?
Instead of String.fromCharCode.apply()
, use e. g. a TextEncoder
. See Uint8Array to string in Javascript
来源:https://stackoverflow.com/questions/38432611/converting-arraybuffer-to-string-maximum-call-stack-size-exceeded