12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <script>
- var url = "ws://ws.anquanzhuli.com/ws?encoding=text&cId=1&gId=641&path=riskPointCount-back&from=aqpt.anquanzhuli.com";
- var ws = new WebSocket(url);
- ws.onopen = function (event) {
- console.log("Connection open ...");
- ws.send("riskPointCount-back");
- }
- ws.onmessage = function (p1) {
- console.log(p1.data);
- appendHtml(document.getElementById('container'), '<li>' + p1.data + '</li>');
- }
- function send() {
- ws.send(document.getElementById('txtInput').value);
- }
- function appendHtml(elem, value) {
- var node = document.createElement("div"),
- fragment = document.createDocumentFragment(),
- childs = null,
- i = 0;
- node.innerHTML = value;
- childs = node.childNodes;
- for (; i < childs.length; i++) {
- fragment.appendChild(childs[i]);
- }
- elem.appendChild(fragment);
- childs = null;
- fragment = null;
- node = null;
- }
- </script>
- </head>
- <body>
- <div>
- <ul id="container">
- </ul>
- <input type="text" id="txtInput"/>
- <input type="button" value="发言" onclick="send()">
- <a target="_blank" href="http://localhost:8899/push/msg?msg=hello from push api">使用API推送消息</a>
- </div>
- </body>
- </html>
|