Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created April 27, 2020 16:20
Show Gist options
  • Save azamsharp/2fe78c3a5f45dadc6a66bec419ceacaf to your computer and use it in GitHub Desktop.
Save azamsharp/2fe78c3a5f45dadc6a66bec419ceacaf to your computer and use it in GitHub Desktop.
// http://www.omdbapi.com/?s=superman&apikey=564727fa
// s and apiKey are called query strings
let moviesList = document.getElementById("moviesList")
let request = new XMLHttpRequest()
// OPTION 1
/*
request.addEventListener('load',function() {
}) */
// OPTION 2
request.onload = function() {
// parse the text as JavaScript Object
let result = JSON.parse(this.responseText)
let liItems = result.Search.map((movie) => {
return `<li>
<label>${movie.Title}</label>
<img src=${movie.Poster}/>
</li>`
})
// converting liItems array to a string and then assigning to the ul
moviesList.innerHTML = liItems.join("")
console.log(liItems)
}
request.open("GET","http://www.omdbapi.com/?s=superman&apikey=564727fa")
request.send()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment