【发布时间】:2020-04-16 15:51:30
【问题描述】:
我正在尝试在 nodejs 中创建一个赞成和反对的系统。客户端javascript应该处理upvote和downvote功能并将数据发送到服务器,服务器将存储用户的决定。
我的问题是如何将数据发送到服务器,如果成功保存了赞成票或反对票,我该如何发回?
客户端:
window.onload = function() {
document
.getElementsByClassName("upvote")[0]
.addEventListener("click", function(event) {
// tell the server that the user upvoted
});
};
我猜我会在服务器上做这样的事情
app.get("/", function(req, res) {
// save req data to a file
if (savedToFile) {
res.send("saved successfully");
}
else {
res.send("error");
}
});
【问题讨论】:
标签: javascript node.js express http server