2016-07-18 3 views
4

이것은 내 코드 라인입니다.배열 버퍼를 문자열로 변환 : 최대 호출 스택 크기 초과

 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(); 

이 요청은 약 3MB 크기의 pdf url을 만들고 있습니다. 재귀 호출이 있어야하지만 재귀 호출은 여기에 표시되지 않는다는 것을 나타내는 동일한 오류가있는 스레드를 읽지 마십시오. 어떤 도움이 필요합니까?

+0

이 요청은 동일한 페이지입니까? 'window.location.href'에 GET 사용? – skobaljic

+0

@skobaljic 예. 현재 페이지는 http://www.cs.columbia.edu/~lok/3101/lectures/02-corejava.pdf입니다. –

+0

동일한 스크립트가 포함 된 동일한 페이지를 호출하면 왜 너무 많은 재귀가 있을까? 스크립트가없는 다른 페이지를 호출 해보십시오. 또는 xhr을 통해 호출하는 경우 스크립트를 다시 출력하지 않거나 매개 변수를 추가하여 호출을 구별합니다. – skobaljic

답변

7

이 오류는 함수 인수의 수 제한 때문에 발생합니다. "RangeError: Maximum call stack size exceeded" Why?

String.fromCharCode.apply() 대신 e를 사용하십시오. 지. a TextEncoder. Uint8Array to string in Javascript

+0

안녕하세요. 필자의 경우'TextEncoder '를 어떻게 사용합니까? 나는이'var base64 = btoa (String.fromCharCode.apply (null, new Uint8Array (blob))); – iamdevlinph

+1

별도의 [질문] (https://stackoverflow.com/questions/49123222/converting-array) -buffer-to-string-maximum-call-stack-size-exceeded) – iamdevlinph

관련 문제