dimanche 8 mars 2015

Removing Note in JavaScript

I have a program that stores user's notes. When a user select the delete button, the program should remove the note. I have tried to use remove() but it does not change anything. The note is not being removed. Any suggestions on how to implement a remove button?



router.post('/delete/:id',function(req, res) {
var username = req.session.username;
var id = ObjectID(req.body.id);
var noteTitle = req.body.title;
var content = req.body.content;

var resultsPage = function(status) {
res.render("delete.jade", {title: status,
noteTitle: noteTitle});
}

var checkUpdate = function(err, result) {
if (err) {
resultsPage("Update Failed");
} else {
resultsPage("Update Succeded");
}
}

if (username) {
notesCollection.remove({_id: id},
{$set: {title: noteTitle,
content: content}},
checkUpdate);
} else {
res.redirect("/?error=Not Logged In");
}
});

Aucun commentaire:

Enregistrer un commentaire