39,085
社区成员
发帖
与我相关
我的任务
分享
var socket = {
start: function () {
var location = "ws://88.88.88.88.8";
this._ws = new WebSocket(location);
this._ws.onopen = this.whenOpen;
this._ws.onmessage = this.whenMessage;
this._ws.onclose = this.whenClose;
},
whenOpen: function (m) {
alert("open!");
},
sendMsg: function (message) {
alert("send!");
if (this._ws) {
this._ws.send(message);
}
},
$(function () {
var json = { username: "abc", age: 33 };
var str = JSON.stringify(json);
socket.sendMsg(str);
}