我的删除代码不工作,我认为甚至没有开火,因为我没有看到我的console.log,我有一个添加按钮,与窗体一起工作,他们看起来一样,这就是为什么我不明白。Jade + mongodb + express.js,删除表单不工作
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' midddleware吗? 在您启动节点服务器的终端中,您能看到POST请求吗? – Komo
是的,我正在使用body-parser,不,我没有在节点服务器上看到任何东西 – Sunkhern