-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontend.js
63 lines (53 loc) · 1.98 KB
/
frontend.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
window.onload = function() {
document.querySelector("#button_bring").onclick = async function(e) {
e.preventDefault()
try {
const dbData = await fetch("http://127.0.0.1:3000/api/helloWorld", {
method: "get",
url: "http://localhost:3000",
}) //fetch("http://localhost:3000/")
//console.log(dbData)
const message = await dbData.json()
document.querySelector("#db").innerHTML = JSON.stringify(message)
} catch(err) {
console.error(err.message)
}
}
document.querySelector("#button_post").onclick = async function(e) {
e.preventDefault()
try {
console.log("clicked")
// const token = getTokenFromUser()
// const price = getPrice(token)
const token = "bitcoin"
const price = 15000
const url = "http://127.0.0.1:3000/api/price"
// var xhr = new XMLHttpRequest();
// xhr.open("POST", url, true);
// xhr.setRequestHeader("Content-Type", "application/json");
// xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
// xhr.send(JSON.stringify({
// token,
// price
// }));
const dbDataResponse = await fetch(url, {
method: 'POST',
mode: "cors",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
token,
price,
})
})
const dbDataJson = await dbDataResponse.json()
// fetch("http://localhost:3000/")
// // console.log(dbData)
// const message = await dbData.json()
document.querySelector("#db2").innerHTML = dbDataJson.price
} catch(err) {
console.error(err.message)
}
}
}