-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (47 loc) · 1.38 KB
/
index.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
document.getElementById("hello").addEventListener("input", myFunction);
const checkHereParagraph = document.getElementById("checkHere");
let value = "";
function myFunction(e) {
value = e.target.value;
httpPost("http://localhost:5000/api");
}
function httpPost(theUrl) {
checkHereParagraph.innerHTML = "";
fetch(theUrl, {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(value)
}).then(response => {
return response.json();
}).then(jsonResponse => {
res = JSON.stringify(jsonResponse)
console.log(typeof res);
checkHereParagraph.innerHTML += res;
}).catch (error => {
console.log(error)
})
// var xmlHttp = new XMLHttpRequest();
// xmlHttp.open("POST", theUrl, true);
// xmlHttp.setRequestHeader("Content-Type", "application/json");
// xmlHttp.send(
// JSON.stringify({
// value,
// })
// );
// console.log(xmlHttp.responseText);
// if (xmlHttp.readyState == 4) {
// if (xmlHttp.status == 200) {
// console.log(xmlHttp.responseText);
// }
// }
// httpGet("http://localhost:5000/api");
}
function httpGet(theUrl) {
var xmlHttp2 = new XMLHttpRequest();
xmlHttp2.open("GET", theUrl, false);
xmlHttp2.send(null);
console.log(xmlHttp2.responseText);
}