I have the following delete method in my express node app:
/* Delete */
router.delete('/objects/object/:id', function(req, res){
var db = req.db;
var collection = db.get('mydb');
collection.remove({ID: req.params.id}, function(error, numberRemoved){
if(error){
console.log(error);
}else{
console.log(numberRemoved + ' docs removed');
req.flash('info','Coupon deleted');
res.send('success');
}
});
});
I call it using jQuery ajax:
$.ajax({
type: 'DELETE',
data: {"_method":"delete"},
url:window.location.pathname
})
.done(function(){
window.location.replace("../1");
})
.fail(function(){
console.log('delete failed');
});
This should be the end of it, but when the object has been deleted from my database, the post function on the same url is called:
router.post('/objects/object/:id', postObject(req,res));
How can I prevent this from happening?
Aucun commentaire:
Enregistrer un commentaire