-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocketBoard.html
37 lines (34 loc) · 949 Bytes
/
socketBoard.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
<html>
<head>
<title>Express Message Board</title>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var socket = io.connect("/");
$.get("/messages", function (data) {
var i = 0;
for (i = 0; i < data.length; i++)
$("#messageBoard").append("<p>" + data[i] + "</p>");
socket.on("message", function (data) {
$("#messageBoard").append("<p>" + data + "</p>");
});
});
$("#sendBtn").click(function () {
var msgText = $("#msgText").val();
socket.send(msgText);
$("#msgText").focus().val("");
});
});
</script>
</head>
<body>
<div class="container">
<div id="messageBoard"></div>
<div>
<input id="msgText" type="text" autofocus placeholder="Your message here"/>
<button id="sendBtn">Send</button>
</div>
</div>
</body>
</html>