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

Shane | TV Channels #172

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
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="browse">
<div id="search-form">
<input type="search" placeholder="Search for a title..." id="show-search">
<button>submit</button>
<button id = "submit-button">submit</button>
</div>

<select id="show-select">
Expand All @@ -26,4 +26,4 @@

<script src="js/tv_browser.js"></script>
</body>
</html>
</html>
48 changes: 46 additions & 2 deletions js/tv_browser.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
// API Docs at:
// http://www.tvmaze.com/api
console.log("The script is running");

// this is the url to search from
var url = "http://api.tvmaze.com/search/shows?q=girls;"


// function to run when event is loaded
var responseGet = function(){
// to format strings into objects
var response = JSON.parse(this.responseText);
// define show from the parsed response
var show = response.show
console.log(response);
console.log(show);
// location to display show
showDetails = document.querySelector("#show-detail");
// display show
showDetails.innerText = show;
}


// a function to send the request for the button
var sendRequest = function(){
// define the location of input
var input = document.getElementById("show-search")
console.log("searching....");
// define request into a variable
var requestGet = new XMLHttpRequest();
console.log("getting request...");
// get the request from the global var url
requestGet.open("get" , url);
console.log("searching the url...")
// send the request
requestGet.send();
console.log("sending request...");

// add an event
requestGet.addEventListener("load", responseGet);

}
// assign the button from
var submitButton = document.querySelector("#submit-button");

//create an event click on button
submitButton.addEventListener("click", sendRequest);
console.log("The button is listening...")