Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
Latest commit
63 lines (42 loc) · 1.45 KB
/
Copy pathindex.html
File metadata and controls
63 lines (42 loc) · 1.45 KB
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
<!DOCTYPE html>
<html>
<headlang="en">
<metacharset="UTF-8">
<title></title>
<scripttype="text/javascript" src="http://code.jquery.com/jquery-2.2.1.min.js"></script>
<script>
$(document).ready(function(){
$('#button').prop('disabled',true);
varconn=newWebSocket('ws://127.0.0.1:8080');
conn.onopen=function(e){
console.log("Connection established!");
$('#button').prop('disabled',false);
};
conn.onmessage=function(e){
console.log(e.data);
$('#messages').append('<span style="background-color: chartreuse;">'+e.data+'</span><br />');
$('#button').prop('disabled',false);
};
conn.onerror=function(e){
console.log(e);
};
$('#chat').submit(function(e){
e.preventDefault();
$('#button').prop('disabled',true);
varmessage=$('#message').val();
conn.send(JSON.stringify({message: message}));
$('#message').val('');
returnfalse;
});
});
</script>
</head>
<body>
<divid="messages">
</div>
<formid="chat" method="post">
<inputtype="text" name="message" id="message">
<inputtype="submit" name="BUTTON" id="button">
</form>
</body>
</html>