fetch API

zenibako.lee
1 min readAug 26, 2019

--

ajax의 구현방법 중 하나.

<!doctype html><html>  <body>    <article>    </article>    <input type="button" value="fetch" onclick=" //add onclick event      fetch('html').then(function(response){ 
//클라이언트가 서버에게 'html'이라는 파일 요청
//이후 .then()를 통해 서버의 응답 완료 후 콜백함수 실행.
(Asynchronous,비동기)
response.text().then(function(text){
//서버에게 'text'로 응답을 받음
document.querySelector('article').innerHTML = text;
//'article'이라는 태그의 innerHTML을 서버에게 받은 text로 변경.
}) }) "> </body></html>

--

--

zenibako.lee
zenibako.lee

Written by zenibako.lee

backend engineer, JS, Node, AWS

No responses yet