-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnote.js
More file actions
143 lines (106 loc) · 5 KB
/
note.js
File metadata and controls
143 lines (106 loc) · 5 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
function addnote() {
// Get the message from the text box
var note = document.getElementById("note").value;
console.log("hi");
// var getUrl = "http://localhost:8085/api/person/findEmail";
var getUrl = "https://crimebusters.tk/api/person/findEmail";
//test
var getOptions = {
method: 'GET',
mode: 'cors',
cache: 'default',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
};
fetch(getUrl, getOptions)
.then(response => {
//error message
if (!response.ok) {
const errorMsg = 'Login error: ' + response.status;
console.log(errorMsg);
return;
}
//if success
console.log("User id successfully obtained");
response.json().then(data => {
console.log(data);
//get id and email from cookie
var id = data.id;
var email = data.email;
console.log("id: " + id);
console.log("note: " + note);
//var login_url = "http://localhost:8085/api/notes/note";
//var baseurl = "https://crimebusters.tk/api/notes/note";
//var baseurl = "https://crimebusters.tk";
var baseurl = "http://localhost:4002";
// Authenticate endpoint
// const login_url = baseurl + '/api/notes/note';
//const login_url = 'http://localhost:4002/api/notes/note';
const login_url = 'https://crimebusters.tk/api/notes/note';
const body = {
email: email,
text: note
};
console.log("body: " + JSON.stringify(body));
// Set Headers to support cross origin
//IMPORTANT!!!!!!! TO SUCCESSFULLY POST, YOU NEED TO REMOVE
// credentials:'include'
//test
// Set Headers to support cross origin
const requestOptions = {
method: "POST",
mode: "cors", // no-cors, *cors, same-origin uguu
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "include", // include, *same-origin, omit
body: JSON.stringify(body),
headers: {
"content-type": "application/json",
},
};
//test test
fetch(login_url, requestOptions)
.then(response => {
// trap error response from Web API
if (!response.ok) {
const errorMsg = 'Login error: ' + response.status;
console.log(errorMsg);
return;
}
response.json().then(data => {
console.log(data);
console.log("hiiiiiiiiiiiii");
console.log("Note success");
var p = document.createElement("p");
var noteSuccessMsg = document.createTextNode("Note successfully saved!");
p.appendChild(noteSuccessMsg);
document.getElementById("noteSuccess").appendChild(noteSuccessMsg);
document.getElementById("mainTable").innerHTML = "";
document.getElementById("mainTable").innerHTML = "<table class='tablelines' id='mainTable'><tr><th>Person Name</th><th>Note</th></tr><tbody id='noteTable'></tbody></table>";
console.log(data);
console.log("email " + data.email);
console.log("note " + data.text);
// if (id == row.userId) {
// make "tr element" for each "row of data"
const tr = document.createElement("tr");
// td for joke cell
const personName = document.createElement("td");
personName.innerHTML = data.email; // add fetched data to innerHTML
// td for joke cell
const noteText = document.createElement("td");
noteText.innerHTML = data.text; // add fetched data to innerHTML
// this builds ALL td's (cells) into tr (row) element
tr.appendChild(personName);
//tr.appendChild(plaintext);
tr.appendChild(noteText);
// this adds all the tr (row) work above to the HTML "result" container
document.getElementById("noteTable").appendChild(tr);
})
})
})
});
// };
//document.getElementById("log").appendChild(logButton);
}
///test