You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
42 lines
1.0 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Title</title>
|
|
</head>
|
|
<body>
|
|
<h1>Всем привет , дети мои!!</h1>
|
|
<div id="output">
|
|
</div>
|
|
|
|
<form id="chatform">
|
|
<input id="text" type="text" />
|
|
<input type="submit" />
|
|
</form>
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
|
|
<script type="text/javascript">
|
|
$(document).ready(function(){
|
|
var url = 'ws://127.0.0.1:8888/chat';
|
|
var socket = new WebSocket(url);
|
|
|
|
socket.onopen = function(){
|
|
console.log("Соединение установлено");
|
|
socket.send("start");
|
|
}
|
|
|
|
socket.onmessage = function (event) {
|
|
console.log(event.data);
|
|
var data = JSON.parse(event.data);
|
|
output = output + '<h3>'+ data.msg +'</h3>';
|
|
$("#output").html(output);
|
|
}
|
|
$('form').submit(function(e){
|
|
e.preventDefault();
|
|
var currentText = $("#text").val();
|
|
socket.send(currentText);
|
|
});
|
|
});
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|