-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
32 lines (32 loc) · 1.27 KB
/
main.js
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
$(document).ready(function () {
$('#title').autocomplete({
source: async function(request, response) {
let data = await fetch(`http://localhost:8000/search?query=${request.term}`)
.then(results => results.json())
.then(results => results.map(result => {
return {
label: result.title,
value: result.title,
id: result._id
}
}))
response(data)
// console.log(response)
},
minLength: 2,
select: function(event, ui) {
console.log(ui.item.id)
fetch(`http://localhost:8000/get/${ui.item.id}`)
.then(result => result.json())
.then(result => {
$('#cast').empty()
result.cast.forEach(cast =>
{
$('#cast').append(`<li>${cast}</li>`)
})
$('img').attr('src',result.poster)
})
}
})
}
)