Mein Löschcode funktioniert nicht und ich denke nicht einmal feuern, da ich nicht meine console.log sehe, habe ich eine Schaltfläche hinzufügen, die mit einem Formular funktioniert und sie gleich aussehen, deshalb verstehe ich es nicht.Jade + mongodb + express.js, löschen Formular funktioniert nicht
app.js:
var db = monk('localhost:27017/mongodb');
Jade:
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");
}
});
});
Verwenden Sie die Middleware 'body-parser'? In dem Terminal, wo Sie Ihren Node-Server gestartet haben, können Sie die POST-Anfrage sehen? – Komo
Ja, ich benutze Body-Parser, nein, ich sehe nichts auf dem Node-Server – Sunkhern