【发布时间】:2016-05-04 07:41:21
【问题描述】:
我的删除代码不起作用,我认为甚至没有触发,因为我没有看到我的 console.log,我有一个与表单一起使用的添加按钮,它们看起来很相似,这就是我不明白的原因.
app.js:
var db = monk('localhost:27017/mongodb');
玉:
extends admin_menu
block content
h1.
Cocktail list
ul
each cocktail, i in cocktaillist
li
p= cocktail.name
form#form_delete_project(name="/admin/delete_cocktail", method="post", action="/admin/delete_cocktail")
input#input_name(type="hidden", placeholder="", name="_id", value="#{cocktail._id}")
button#submit_project(type="submit") delete
index.js:
router.post('/admin/delete_cocktail', function(req, res) {
console.log(id)
// Set our internal DB variable
var db = req.db;
// Get our form values. These rely on the "name" attributes
var id = req.body._id;
// Set our collection
var collection = db.get('cocktailcollection');
// Submit to the DB
collection.remove({
"_id":id
}, function (err, doc) {
if (err) {
// If it failed, return error
res.send("There was a problem removing the information to the database.");
}
else {
// And forward to success page
res.redirect("/admin/cocktail_list");
}
});
});
【问题讨论】:
-
您使用的是
body-parser中间件吗?在您启动节点服务器的终端中,您能看到 POST 请求吗? -
是的,我正在使用 body-parser,不,我在节点服务器上看不到任何东西