ex01jQuery.html

최현주·2023년 10월 23일
1
</head>
<body>
	<button onclick="getData()"Get 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
          const getData=()=>{

          rank, movieNm, openDt
          const getData=()=>{
              $.ajax({
                  // 어떤 방식으로 통신할 건지
                  type : 'get',
                  // 어디랑 통신할 건지
                  url  : movieUrl,
                  //  통신에 성공했을 때 실행할 로직
                  success : (response)=>{
                      // response => 응답 데이터
                      // console.log(response.boxOfficeResult.dailyBoxOfficeList[0].movieNm);
          let movieList = response.boxOfficeResult.dailyBoxOfficeList;
          //console.log(movieList[i].rank,movieList[i].movieNm,movieList[i].openDt);

          //for문으로 출력하기
          //방법 1
          for(let i=0;i<movieList.length;i++){
              console.log(movieList[i].rank, movieList[i].movieNm,movieList[i].openDt);

          // 방법 2
          for(let i of movieList{
              console.log(i.rank,i.movieNm,i.openDt);

          // 방법 2
          movieList.forEach((element)=>{
              console.log(element.rank,element.movieNm,elemenet.openDt);

          // 통신에 실패했을 때 실행할 로직
          error : ()=>{}
})
}
</script>
</body>
</html>
        
profile
갓벽한 개발자

0개의 댓글