자바스크립트
fetch 사용하기 본문
오늘은 fetch를 사용해보겠습니다.
1. fetch란?
fetch는 주로 api 형식으로 사용합니다.
2. fetch 사용 예제
1. json
fetch('data.json')
.then(response => response.json())
.then(data=>{console.log(data)})
2. xml
fetch('data.xml')
.then(response => response.text())
.then(str => new window.DOMParser().parseFromString(str, "text/xml"))
.then(data => {console.log(data)})
3. 마무리
오늘도 짧은 글 읽어주셔서 감사합니다!
'자바스크립트' 카테고리의 다른 글
반복과정을 진행하는 for문 알아보기 (0) | 2023.04.23 |
---|---|
location 알아보기 (0) | 2023.04.22 |
선택자의 텍스트 정하기 (0) | 2023.04.22 |
return문 사용하기 (0) | 2023.04.22 |
자바스크립트에서 alert, confirm, prompt 사용하기 (0) | 2023.04.22 |
댓글