-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
40 lines (40 loc) · 1.69 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
<!doctype html>
<html>
<head>
<title>Socket Test</title>
<script type="text/javascript" src="jquery-1.11.1.js"></script>
<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script type="text/javascript">
$("document").ready(function() {
var socket = io.connect('http://localhost:3000');
var requestId = [];
$('.testButton').click(function() {
requestId['testButton'] = Date.now();
socket.emit('weightRequest', requestId['testButton']);
});
$('#testInput').click(function() {
requestId['testInput'] = Date.now();
socket.emit('weightRequest', requestId['testInput']);
});
socket.on('weightResponse', function (data) {
console.log(data);
console.log(data.requestId + ' ' + requestId['testButton']);
console.log(data.weight);
if (data.requestId === requestId['testButton']) {
console.log('eureka');
$('#test').html('<p>' + data.weight + '</p>');
} else if (data.requestId == requestId['testInput']) {
$('#testInputField').val(data.weight);
}
});
});
</script>
</head>
<body>
<h1>Socket Test</h1>
Server Response: <input id="testInputField" type="text" name="response"><br />
<button id="testInput" >Submit</button>
<div id="test"> </div>
<button class="testButton">Test</button>
</body>
</html>