我在 Sails.js 中使用套接字
以下是示例客户端代码:
socket.get('/message/send', {from: userId, to: recepientId, content: textMessage});
这就是我在 Controller (服务器)中获取数据的方式:
var to = req.param('to');
var from = req.param('from');
var content = req.param('message');
现在,由于我将数据作为 json 发送,我想将其作为 json 对象获取。所以Message最终是一个模型,我想直接使用json对象将数据存入db。
当我使用 socket.emit('channel',{userId: "someId"})
时,类似的事情对我有用
所以我确实在 socket.on('channel', function(userJsonObject){});
那么我在使用socket.get()
最佳答案
不知道为什么它如此重要,但是类似
socket.get('/message/send', {
message: JSON.stringify({from: userId, to: recepientId, content: textMessage})
});
应该可以。
关于javascript - Sails.js,获取请求参数 json 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23566328/