-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
70 lines (63 loc) · 2.66 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
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>chatApp</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"
integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous">
</script>
<script src="/socket.io/socket.io.js" node></script>
</head>
<body>
<div class="container">
<br>
<div class="jumbotron">
<h1 class="display-4">Send Message</h1><br>
<input type="text" name="name" placeholder="Name" id="name" class="form-control"><br>
<input type="text" name="message" placeholder="Message" id="message" class="form-control"><br>
<button id="send" class="btn btn-success">Send</button>
</div>
<div id="messages">
</div>
</div>
<script>
var socket = io()
$(() => {
getMessages();
// console.log("Page loaded!");
var messages = [];
$('#send').click(() => {
var message = {
name: $('#name').val(),
message: $('#message').val()
}
$('#message').val('');
PostMessages(message);
})
})
socket.on('message',addMessages)
function addMessages(message) {
console.log(message);
$("#messages").append(`<h4 class="mb-0"> ${message.name}</h4><p class="mt-0">${message.message}</p></br>`)
}
function getMessages() {
console.log("getmessage");
$.get('https://amezchatapp.herokuapp.com/messages', (data) => {
// console.log(data);
data.forEach(addMessages)
})
}
function PostMessages(message) {
$.post('https://amezchatapp.herokuapp.com/messages', message)
}
</script>
</body>
</html>