nowjs的正确使用方法
这是我目前使用nowjs的方式,但是这种使用方式是错误的吗?
客户端:
$('#guestbook_form').validate({
rules: {
message: {
required: true, maxlength: 1000
}
},
submitHandler: function(form) {
now.sendGb($(form).serializeObject());
}
});
now.pushMessage = function(message) {
$('#guestbook_records').append(message);
};
服务器:(
everyone.now.sendGb = function(message) {
client.query(
'INSERT INTO guestbook SET owner_id = ?, user_id = ?, message = ?',
[message.id, message.user_id, sanitize(message.message).entityEncode().trim()]
);
everyone.now.pushMessage(message.message);
};
当然,此代码还有一些其他问题,但仅作为示例)
我还应该如何使用 nowjs?
感谢您的帮助
This is currently the way i use nowjs, but is this wrong way to use it?
client:
$('#guestbook_form').validate({
rules: {
message: {
required: true, maxlength: 1000
}
},
submitHandler: function(form) {
now.sendGb($(form).serializeObject());
}
});
now.pushMessage = function(message) {
$('#guestbook_records').append(message);
};
server:
everyone.now.sendGb = function(message) {
client.query(
'INSERT INTO guestbook SET owner_id = ?, user_id = ?, message = ?',
[message.id, message.user_id, sanitize(message.message).entityEncode().trim()]
);
everyone.now.pushMessage(message.message);
};
(Of course theres a few other problems with this code, but but just as an example)
How else should i use nowjs?
Thanks for helping out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是为了一般的稳健性,我建议
在将消息发布给每个人之前仔细检查插入是否发生且没有错误。
Just for general robustness I would recommend
This double checked that the INSERT happened without an error before posting the message to everyone.