Skip to content

Commit

Permalink
Merge pull request #142 from behdadset/master
Browse files Browse the repository at this point in the history
Week07
  • Loading branch information
aleksanderbrymora authored Jun 30, 2020
2 parents 0e2ae94 + cca4cd7 commit 1e3ab9a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions behdad_setoodegan/week-07/google_books/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
15 changes: 15 additions & 0 deletions behdad_setoodegan/week-07/google_books/index.html
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>
26 changes: 26 additions & 0 deletions behdad_setoodegan/week-07/google_books/js/gBooks.js
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)





0 comments on commit 1e3ab9a

Please sign in to comment.