-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (30 loc) · 1.07 KB
/
script.js
File metadata and controls
33 lines (30 loc) · 1.07 KB
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
32
33
document.getElementById("btn-search").addEventListener("click", async () => {
const value = document.getElementById("search-value").value;
const url = `https://online-movie-database.p.rapidapi.com/auto-complete?q=${value}`;
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'd5954b5b9emsh7c9a963540a5437p1ea164jsn848d2c0c6f4f',
'X-RapidAPI-Host': 'online-movie-database.p.rapidapi.com'
}
};
try {
const response = await fetch(url, options);
const data = await response.json();
const cards = document.getElementById("cards");
cards.innerHTML = '';
data.d.forEach(element => {
const card = document.createElement("div");
card.innerHTML = `
<div class="card">
<img src="${String(element.i.imageUrl)}" alt="movie image">
<h1>${element.l}</h1>
<button>Watch Now</button>
</div>
`;
cards.append(card);
});
} catch (error) {
console.error(error);
}
});