ws.html 898 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <div>
  9. <ul id="container">
  10. </ul>
  11. <input type="text" id="txtInput"/>
  12. <input type="button" value="发言" onclick="send()">
  13. <a target="_blank" href="http://localhost:8899/push/msg?msg=hello from push api">使用API推送消息</a>
  14. </div>
  15. </body>
  16. <script src="https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js"></script>
  17. <script>
  18. var sock = new SockJS('ws://ws.anquanzhuli.com/ws?encoding=text&cId=1&gId=641&path=riskPointCount-back&from=aqpt.anquanzhuli.com');
  19. sock.onopen = function () {
  20. console.log('open');
  21. sock.send('test');
  22. };
  23. sock.onmessage = function (e) {
  24. console.log('message', e.data);
  25. sock.close();
  26. };
  27. sock.onclose = function () {
  28. console.log('close');
  29. };
  30. </script>
  31. </html>