-
-
Save azamsharp/2fe78c3a5f45dadc6a66bec419ceacaf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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