-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyscript.js
86 lines (53 loc) · 1.72 KB
/
myscript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
$(document).ready(function(){
$("#myform").submit(function(e){
e.preventDefault();
var search = $("#books").val();
if(search=='')
{
alert("Please enter something in the field");
}
else{
var url='';
var img='';
var title='';
var author='';
console.log("Search for "+search);
$.get("https://www.googleapis.com/books/v1/volumes?q="+search,function(response){
var table = $('<table>');
table.attr('border','1');
var tr = $('<tr>');
var td = $('<td>');
td.html('Preview');
tr.append(td);
td = $('<td>');
td.html("Title");
tr.append(td);
td = $('<td>');
td.html('Authors');
tr.append(td);
table.append(tr);
for(i=0;i<response.items.length;i++){
title=$('<h5>'+response.items[i].volumeInfo.title + '</h5>');
author=$('<h5>'+response.items[i].volumeInfo.authors + '</h5>');
img=$('<img><a href=' + response.items[i].volumeInfo.imageLinks.thumbnail + '></a>');
response.items[i].volumeInfo.imageLinks.thumbnail
var tr = $('<tr>');
var td = $('<td>');
td.html(img);
tr.append(td);
td = $('<td>');
td.html(response.items[i].volumeInfo.title);
tr.append(td);
td = $('<td>');
td.html(response.items[i].volumeInfo.authors);
tr.append(td);
url=response.items[i].volumeInfo.imageLinks.thumbnail;
img.attr('src',url);
table.append(tr);
$('body').append(table);
}
});
}
});
return false;
});