I'm building a Node/Mongo/Express/Jquery application that's correctly processing a DELETE
request but it does not refresh the page afterwards to update its contents.
I tried the answer posted for this question, but after including
req.method = 'GET'
inside the router.delete(url, callback)
code block I was not getting different results.
CODE:
router.delete('/formula-list/:id', function(req, res){
var db = req.db;
var collection = db.get('formulas');
var id = req.params.id;
var query = { "_id": id };
collection.findOneAndDelete(query);
req.method = 'GET';
res.redirect('/formula-list');
});
Again, the 'DELETE' request works just fine using a jQuery AJAX call, but I want the page to update to reflect that an item has been deleted from the database.
I've also tried the following to no avail:
router.delete('/formula-list/:id', function(req, res){
var db = req.db;
var collection = db.get('formulas');
var id = req.params.id;
var query = { "_id": id };
collection.findOneAndDelete(query);
collection.find({}, {}, function(e, docs){
res.render('formula-list', {
formulas: docs,
title: 'Your Formulas',
description: `List of saved user formulas from the formula generator`,
ID: 'formula-list',
keywords: 'formula generator, health kismet, nutraceutical formula builder'
});
});
});
The idea here is that once I delete the item from the database I I re-send the collection to the URL to be re-displayed. I did this with and without adding req.method = 'GET'
but this did not work either.
Thank you for your consideration.