-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.js
127 lines (118 loc) · 4.61 KB
/
library.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//var request = new XMLHttpRequest();
var likedbooks = document.getElementById("liked-books");
var pickedbooks = document.getElementById("picked-books");
var rotationbooks = document.getElementById("rotation-books");
var userdata = JSON.parse(sessionStorage.user);
var i;
for(i=0;i<userdata.data.ratedBooks.length;i++){
const bookdiv = document.createElement('div');
const booktitle = document.createElement('h4');
const bookauthor = document.createElement('h6');
const booklink = document.createElement('a');
const request = new XMLHttpRequest();
const message = 'http://localhost:7000/act?role=home&cmd=getbook&bookid='+userdata.data.ratedBooks[i].id
if ("withCredentials" in request) {
request.open('GET', message, true);
} else if (typeof XDomainRequest != "undefined") {
request = new XDomainRequest();
request.open('GET', message);
}
request.onload = function (response) {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
console.log(data)
booktitle.innerHTML = data.data.title;
bookauthor.innerHTML = data.data.author;
booklink.innerHTML = "Read More";
booklink.href = data.data.url;
bookdiv.appendChild(booktitle);
bookdiv.appendChild(bookauthor);
bookdiv.appendChild(booklink);
likedbooks.appendChild(bookdiv);
}
request.send();
}
const request = new XMLHttpRequest();
const message = 'http://localhost:7000/act?role=home&cmd=get&content=recommendation&readerid='+userdata.data.id
if ("withCredentials" in request) {
request.open('GET', message, true);
} else if (typeof XDomainRequest != "undefined") {
request = new XDomainRequest();
request.open('GET', message);
}
request.onload = function (response) {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
console.log(data)
for(i=0;i<data.data.length;i++){
const bookdiv = document.createElement('div');
const booktitle = document.createElement('h4');
const bookauthor = document.createElement('h6');
const booklink = document.createElement('a');
const requests = new XMLHttpRequest();
const mess = 'http://localhost:7000/act?role=home&cmd=getbook&bookid='+data.data[i].id
if ("withCredentials" in requests) {
requests.open('GET', mess, true);
} else if (typeof XDomainRequest != "undefined") {
requests = new XDomainRequest();
requests.open('GET', mess);
}
requests.onload = function (response) {
// Begin accessing JSON data here
var newdata = JSON.parse(this.response);
console.log(newdata)
booktitle.innerHTML = newdata.data.title;
bookauthor.innerHTML = newdata.data.author;
booklink.innerHTML = "Read More";
booklink.href = newdata.data.url;
bookdiv.appendChild(booktitle);
bookdiv.appendChild(bookauthor);
bookdiv.appendChild(booklink);
pickedbooks.appendChild(bookdiv);
}
requests.send();
}
}
request.send();
const therequest = new XMLHttpRequest();
const themessage = 'http://localhost:7000/act?role=home&cmd=get&content=rotation&readerid='+userdata.data.id
if ("withCredentials" in therequest) {
therequest.open('GET', themessage, true);
} else if (typeof XDomainRequest != "undefined") {
therequest = new XDomainRequest();
therequest.open('GET', themessage);
}
therequest.onload = function (response) {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
console.log(data)
for(i=0;i<data.data.length;i++){
const bookdiv = document.createElement('div');
const booktitle = document.createElement('h4');
const bookauthor = document.createElement('h6');
const booklink = document.createElement('a');
const requests = new XMLHttpRequest();
const mess = 'http://localhost:7000/act?role=home&cmd=getbook&bookid='+data.data[i].id
if ("withCredentials" in requests) {
requests.open('GET', mess, true);
} else if (typeof XDomainRequest != "undefined") {
requests = new XDomainRequest();
requests.open('GET', mess);
}
requests.onload = function (response) {
// Begin accessing JSON data here
var newdata = JSON.parse(this.response);
console.log(newdata)
booktitle.innerHTML = newdata.data.title;
bookauthor.innerHTML = newdata.data.author;
booklink.innerHTML = "Read More";
booklink.href = newdata.data.url;
bookdiv.appendChild(booktitle);
bookdiv.appendChild(bookauthor);
bookdiv.appendChild(booklink);
rotationbooks.appendChild(bookdiv);
}
requests.send();
}
}
therequest.send();