ex02fetch.html

최현주·2023년 10월 23일
1

python
<buttonGet Data❤</button>
<script>
  let movieUrl = 'https://kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=cdb98d81b9d2072f4c22c0e85d19d6d2&targetDt=20231001'
  // jQuery를 통한 비동기통신

  // 영화진흥위원회 API를 가져와서
  // 일일 박스오피스 영화 TOP10의
  // 순위, 영화 이름, 개봉일 출력
  // rank, movieNm, openDt
  // http와 https의 차이 : 둘다 동일한 결과로 출력됨. s는 security라는 뜻으로 좀더 보안이 강화된것.
  
  const getData = () => {
  	fetch(movieUrl)
  	.then(res=>res.json())
  	.then((data)=>{
  		// console.log(data.boxOfficeResult.dailyBoxOfficeList);
  		let movieList = data.boxOfficeResult.dailyBoxOfficeList;
  			//console.log(movieList[0].rank,movieList[0].movieNm,movieList[0].openDt);
            for(let i=0;i<movieList.length;i++){
            	console.log(movieList[i].rank,movieList[i].movieNm,movieList[0].openDt);
                }
         })
         .catch((err)=>{
         	alert('에러입니다!')
            console.log(err)
            })
            }
            </script>
        </body>
        </html>
profile
갓벽한 개발자

0개의 댓글