-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
57 lines (53 loc) · 1.63 KB
/
index.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
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<br />
<div class="jumbotron">
<h1>Send Message</h1>
<br />
<input id="name" type="form-control" placeholder="Name" />
<br>
<textarea id="message" type="form-control" placeholder="Message" /></textarea>
<br>
<button id="send" class="btn btn-success">Send</button>
</div>
<div id="messages"></div>
</div>
<script>
$(() => {
$('#send').click(() => {
var message = { name: $("#name").val(), message: $("#message").val()};
postMessage(message);
console.log('toto je click');
});
getMessages();
});
function addMessages(message) {
$('#messages').append(
`<h4> ${message.name} </h4> <p> ${message.message}`
);
console.log('toto je addMessage');
}
function getMessages() {
$.get('http://localhost:3000/messages', (data) => {
data.forEach(addMessages);
});
}
function postMessage(message) {
$.post('http://localhost:3000/messages', message);
}
</script>
</body>
</html>