[3] AJAX - text()

o:kcalb·2022년 12월 30일
0

Ajax

목록 보기
3/9
post-thumbnail

1. text()

인터페이스의 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()); 는 주석 필수이다.

profile
모든 피드백 받습니다 😊

0개의 댓글

관련 채용 정보