-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.js
More file actions
60 lines (55 loc) · 2.26 KB
/
Client.js
File metadata and controls
60 lines (55 loc) · 2.26 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
"use strict";
(function () {
window.addEventListener("load", init);
function init() {
document.getElementById("echo-btn").addEventListener("click", requestEcho);
document.getElementById("add-btn").addEventListener("click", addEcho);
document.getElementById("del-btn").addEventListener("click", deleteEcho);
// add 2 more lines
}
function checkStatus(response) {
if (!response.ok) {
throw Error("Error in request: " + response.statusText);
}
return response;
}
function requestEcho() {
const contents = document.getElementById("what-to-echo").value;
fetch("game?rank=" + contents)
.then(checkStatus)
.then(resp => resp.text())
.then(resp => {
document.getElementById("echoed").textContent = resp;
})
.catch(console.error);
}
function addEcho() {
const rank = document.getElementById("rank").value; // change this
const name = document.getElementById("name").value;
const platform = document.getElementById("platform").value;
const year = document.getElementById("year").value;
const genre = document.getElementById("genre").value;
const publisher = document.getElementById("publisher").value;
const na_sales = document.getElementById("na_sales").value;
const eu_sales = document.getElementById("eu_sales").value;
const jp_sales = document.getElementById("jp_sales").value;
const other_sales = document.getElementById("other_sales").value;
const global_sales = document.getElementById("global_sales").value;
fetch("game", { method: "POST", headers: {'Content-Type': 'application/json'}, body: JSON.stringify(>
rank: rank, name: name, platfrom: platform, year: year,
genre: genre, publisher: publisher, na_sales: Number(na_sales),
eu_sales: Number(eu_sales), jp_sales: Number(jp_sales), other_sales: Number(other_sales),
global_sales: Number(global_sales)
}), }) // change this
.then(checkStatus)
.then(resp => resp.text())
.catch(console.error);
}
function deleteEcho() {
const contents = document.getElementById("what-to-delete").value; // change this
fetch("game?rank=" + contents, { method: "DELETE" })
.then(checkStatus)
.then(resp => resp.text())
.catch(console.error);
}
})();