服务器.js
socket.on('adduser', username, successcallback){
if(users.hasOwnProperty(username)){
} else {
socket.username = username;
users[username] = { name: username };
socket.emit('updatechat', 'SERVER', 'you have connected');
socket.broadcast.emit('updatechat', 'SERVER', username + ' has connected');
io.sockets.emit('updateusers', users);
successcallback({ msg: 'User ' + username + ' has been successfully added' });
}
});
索引.html
socket.on('connect', function(){
var username = prompt('Whats your name?');
socket.emit('adduser', username, function(data){
console.log(data);
});
});
这使我的应用程序崩溃。这不是应该如何实现回调吗?