Created
December 21, 2016 20:18
-
-
Save rbk/254d92c3eec0ffbfcb57db8490d67028 to your computer and use it in GitHub Desktop.
Movie Search
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<input type="text" id="input"> | |
<pre id="output"></pre> | |
<script> | |
const input = document.getElementById('input'); | |
const out = document.getElementById('output'); | |
input.addEventListener('keyup', searchMovies); | |
function searchMovies(){ | |
let html = ''; | |
var string = document.getElementById('input').value; | |
fetch('http://www.omdbapi.com/?s=' + string).then(function(res){ | |
return res.json() | |
}).then(data=>{ | |
if(data&&data.Search){ | |
data = data.Search | |
data.forEach(obj=>html+=`<div><a target="_blank" href="${obj.Poster}">${obj.Title}</div>`) | |
} | |
out.innerHTML = html; | |
// out.innerHTML = JSON.stringify(data, null, 2); | |
}) | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment