-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsocket.html
46 lines (44 loc) · 1.08 KB
/
websocket.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
<html>
<head>
<meta charset="utf-8">
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</head>
<body>
<input type="text" id="price"/><input type="button" value="Bid" id="bid_button"/>
The data should then show up up below:
</p>
<pre id="container">
</pre>
<script type="text/javascript">
var ip_host = "192.168.1.9";
//var ip_host = "192.168.100.64";
var ws = new WebSocket("ws://"+ip_host+":8888/ws");
ws.onopen = function() {
console.log("Connected to WebSocket");
};
ws.onmessage = function (evt) {
document.getElementById("container")
.appendChild(document.createTextNode(evt.data + "\n"));
};
function sendMess(){
var mess = document.getElementById("mess").value;
ws.send(mess);
}
$(document).ready(function(){
$('#bid_button').click(function(){
$.ajax({
url: "http://"+ip_host+":8888/bid/1",
type: "PUT",
data: {'price': $('#price').val()},
success: function(result){
console.log(result);
}
})
});
});
</script>
</body>
</html>