-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
71 lines (59 loc) · 2.43 KB
/
client.js
File metadata and controls
71 lines (59 loc) · 2.43 KB
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
document.getElementById('insertButton').addEventListener('click', function(){
const xhr = new XMLHttpRequest();
//getting the values of each textBox
var a = document.getElementById('Author').value
var t = document.getElementById('Title').value
var g = document.getElementById("dropList");
var gender = g.options[g.selectedIndex].value;
// document.getElementById('dropList').onchange = function(){
// if (this.value == 'Science fiction') {
// var optionID=document.getElementById('1');
// var g = optionID.value;
// }
// if (this.value == 'Satire') {
// var optionID=document.getElementById('2');
// var g = optionID.value;
// }
// if (this.value == 'Drama') {
// var optionID=document.getElementById('3');
// var g = optionID.value;
// }
// if (this.value == 'Action and Adventure') {
// var optionID=document.getElementById('4');
// var g = optionID.value;
// }
// if (this.value == 'Romance') {
// var optionID=document.getElementById('5');
// var g = optionID.value;
// }
// if (this.value == 'Mystery') {
// var optionID=document.getElementById('6');
// var g = optionID.value;
// }
// if (this.value == 'Horror') {
// var optionID=document.getElementById('7');
// var g = optionID.value;
// }
// }
var p = document.getElementById('Price').value
xhr.open('POST','http://localhost:8081/books/',true); // true = asynchronous
xhr.send('{"Author":"' + a + '","Title":"' + t + '","Gender":"' + gender + '","Price":"' + p + '"}');
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200){
alert("information sent successfully")
alert(xhr.responseText);
}
};
});
document.getElementById('searchButton').addEventListener('click', function(){
const xhr = new XMLHttpRequest();
xhr.open('GET','http://localhost:8081/books/:',true); // true = asynchronous
xhr.send();
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200){
alert(xhr.responseText);
newObject = JSON.parse(xhr.responseText);
//alert(newObject.); // NEED SPECIFIC STRING THERE LIKE lastName
}
};
});