-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmyfile.html
48 lines (43 loc) · 875 Bytes
/
myfile.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Node delivered HTML
</head>
<body>
<div>
<h1>Send JSON to Node</h1>
<button onClick="sendJSON()">Send</button>
<p id ="result">
</p>
</div>
<script>
var myData = [
{
"name": "Bill",
"age": 20
},
{
"name": "Lisa",
"age": 40
},
{
"name": "Ant",
"age": 80
}
]
function sendJSON(){
var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("result").innerHTML =
this.responseText;
}
};
xmlhttp.open("POST", "http://localhost:3000");
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send(JSON.stringify(myData));
}
</script>
</body>
</html>