인터페이스의 text()
메서드는 스트링을 가져와 완료될 때까지 읽는다.
<div>
<div onclick="
fetch('html').then(function(response){
response.text().then(function(text){
// console.log(response); //response 객체 정보
// console.log(response.text()); //response의 text()
document.querySelector('article').innerHTML = text;
});
});
">HTML</div>
</div>
<article>
</article>
궁금해서 resopnse.text()
를 console.log 해 보았다.
결과는 출력이 된다!
🙄 하지만 텍스트는 한 번만 읽혀서text()
를 이용해 무언가를 실행한다면 에러가 뜬다.
따라서, 실제 작업을 할 때는 console.log(response.text());
는 주석 필수이다.