Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEI-24 Joey #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@

<script src="js/tv_browser.js"></script>
</body>
</html>
</html>
79 changes: 79 additions & 0 deletions js/tv_browser.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,81 @@
// API Docs at:
// http://www.tvmaze.com/api

function get (url) {

return new Promise ( (resolve, reject) => {
let request = new XMLHttpRequest();

request.addEventListener('load', function() {
resolve(this.response);
})

request.addEventListener('error', function() {
reject(this.error);
})

request.open('GET', url);

request.send()
})
}

function submit () {

let input = document.getElementById('show-search');
let url = input.value;
console.log(url);

return get ('http://api.tvmaze.com/search/shows?q='+url)
.then( response => {
let jsonResponse = JSON.parse(response);

jsonResponse.forEach ( show => {
console.log(show.show.name);
let option = document.createElement('option');
option.setAttribute('value', show.show.id);
option.textContent = show.show.name;
document.getElementById('show-select').appendChild(option);
})

document.getElementById('show-select').addEventListener('change', function(){
console.log('hello');
})
})

.catch( response => {
console.log('beep! beep! error!')
})

}

// function responseHandler () {

// // console.log('response text', this.responseText);

// let response = JSON.parse(this.responseText);
// console.log(response);

// response.forEach ( show => {
// console.log(show.show.name);
// let option = document.createElement('option');
// option.textContent = show.show.name;
// document.getElementById('show-select').appendChild(option);
// })

// var showDetails = document.getElementById('show-detail');
// }

// function submit (event) {

// let input = document.getElementById('show-search');
// let url = input.value;
// console.log(url);

// var request = new XMLHttpRequest();
// request.addEventListener('load', responseHandler);
// request.open('GET', 'http://api.tvmaze.com/search/shows?q='+url);
// request.send();
// }

document.querySelector('button').addEventListener('click', submit);