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

