본 내용은 내일배움캠프에서 활동한 내용을 기록한 글입니다.
const options = {
method: 'GET',
headers: {
accept: 'application/json',
Authorization: ''
}
};
fetch('https://api.themoviedb.org/3/movie/top_rated?language=en-US&page=1', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
fetch('https://api.themoviedb.org/3/movie/top_rated?language=en-US&page=1', options)
.then(res => res.json())
.then(async (res) => {
console.log(res.results);
res.results.forEach(item => {
appendCard(item.id, item.title, item.overview, item.poster_path, item.vote_average, $movieCards);
movieDataList.push(item); // 검색에서 사용할 전역 데이터 리스트
});
})
.catch(err => console.error(err));
const appendCard = (id, title, overview, posterPath, voteAverage, area) => {
const html_tmp = `
<div class="col">
<div class="card">
<img src="https://image.tmdb.org/t/p/w200${posterPath}" class="card-img-top" alt="..."token interpolation">${id}')">
<div class="card-body">
<h5 class="card-title" style="font-weight: bold;"> ${title} </h5>
<br>
<p class="card-text"> ${overview} </p>
<p class="vote_rate"><b> Rating : ${voteAverage} </b></p>
</div>
</div>
</div>
`
area.insertAdjacentHTML("beforeend", html_tmp);
}
document.querySelector()
로 innerHTML이 동작하지 않음