/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/SignalR/samples/SignalRSamples/wwwroot/ws.html
44 строки
1 KB
Ryan Brandenburg
Reorganize source code in preparation to move into aspnet/AspNetCore
27 ноя 2018, 21:40
27 ноя 2018, 21:40
2033096
Код
Авторство
О чём код?
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script> document.addEventListener('DOMContentLoaded', () => { var ws = new WebSocket(`ws://${document.location.host}/chat`); ws.onopen = function () { console.log('Opened!'); }; ws.onmessage = function (event) { var child = document.createElement('li'); child.innerText = event.data; document.getElementById('messages').appendChild(child); }; ws.onclose = function (event) { console.log('Closed!'); }; document.getElementById('sendmessage').addEventListener('submit', event => { let data = document.getElementById('data').value; ws.send(data); event.preventDefault(); }); }); </script> </head> <body> <h1>WebSockets</h1> <form id="sendmessage"> <input type="text" id="data" /> <input type="submit" value="Send" /> </form> <ul id="messages"> </ul> </body> </html>