var ws = new WebSocket('ws://test.xubean.top/ws/chat/'); // 建立 web socket 连接成功触发事件 ws.onopen = function () { console.log("success") }; ws.onclose = function () { console.log("failed") };