Converting arraybuffer to string : Maximum call stack size exceeded

你离开我真会死。 提交于 2019-12-30 17:39:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!