생활코딩

Coding Everybody

코스 전체목록

닫기

fetch API polyfill

수업소개

2018년 현재 fetch API는 비교적 최신 기능입니다. 따라서 아직 지원되지 않는 브라우저를 사용자가 사용하는 경우 동작하지 않을 수 있습니다. polypill을 이용하면 fetch API를 지원하지 않는 웹브라우저에서도 이용할 수 있습니다. 지원되지 않는 브라우저에서 코드가 실행되면 polyfill 이 활성화되서 대신 동작하게 됩니다. 이번 시간에는 fetch API의 ployfill을 적용해봅니다. 

 

 

 

강의

 

수업에서 사용하는 polyfill 바로가기

 

소스코드

변경사항

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <script src="../fetch.js"></script>
</head>
<body>
  <script>
    var result = fetch('https://api.github.com')
    result.then(function(response) {
      console.log('response', response)
      console.log('header', response.headers.get('Content-Type'))
      return response.text()
    }).then(function(text) {
      console.log('got text', text)
    }).catch(function(ex) {
      console.log('failed', ex)
    })
  </script>
</body>
</html>

 

댓글

댓글 본문
버전 관리
egoing
현재 버전
선택 버전
graphittie 자세히 보기