-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from behdadset/master
Week07
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"git.ignoreLimitWarning": true | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Google Books Ajax</title> | ||
</head> | ||
<body> | ||
<h1>Google Books</h1> | ||
<h2>Pleas enter the book name:</h2> | ||
<input type="text" id="bookName" placeholder="Enter book name ..."> | ||
<button id = "searchBox">Search</button> | ||
<script src="js/gBooks.js" ></script><br><br> | ||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const xhr = new XMLHttpRequest(); | ||
|
||
const fetchFact = function(){ | ||
|
||
title = document.getElementById("bookName").value; | ||
xhr.onreadystatechange = function(){ | ||
if(this.readyState != 4) return; | ||
|
||
const img = document.createElement('img') | ||
const data = JSON.parse(this.responseText) | ||
imageLink = data["items"][0]["volumeInfo"]["imageLinks"]["thumbnail"] | ||
img.src = imageLink | ||
document.body.appendChild(img) | ||
} | ||
|
||
|
||
xhr.open('GET', `https://www.googleapis.com/books/v1/volumes?q=title:${title}`, true); | ||
xhr.send(); | ||
} | ||
|
||
document.getElementById('searchBox').addEventListener('click', fetchFact) | ||
|
||
|
||
|
||
|
||
|