Notice
Recent Posts
Recent Comments
Link
«   2025/10   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

자바스크립트

fetch 사용하기 본문

자바스크립트

fetch 사용하기

javascript0108 2023. 4. 22. 14:46

오늘은 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. 마무리

 

오늘도  짧은 글 읽어주셔서 감사합니다!

댓글