-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
34 lines (29 loc) · 961 Bytes
/
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
<!DOCTYPE html>
<html>
<head>
<title>ChatJS</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="history"></div>
<form id="chat">
<input type="text" id="msg_text" name="msg_text" />
<input type="submit" value="Send!" />
</form>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
var socket = io.connect();
$("form#chat").submit(function(e) {
e.preventDefault();
socket.emit("send message", $(this).find("#msg_text").val(), function() {
$("form#chat #msg_text").val("");
});
});
socket.on("update messages", function(msg){
var final_message = $("<p />").text(msg);
$("#history").append(final_message);
});
</script>
</body>
</html>