ExpressJS - res.redirect after DELETE request
I know this is late, but for anyone who sees this later, you can also manually reset the HTTP method to GET which should also work
exports.remove = function(req, res) { var postId = req.params.id; Post.remove({ _id: postId }, function(err) { if (!err) { console.log('notification!'); res.send(200); } else { console.log('error in the remove function'); res.send(400); } //Set HTTP method to GET req.method = 'GET' res.redirect('/forum'); });};
@ewizard 's solution is great if you can fix this on the front end. However, if you want to fix this on the back end, you can add an optional Status Code argument to res.redirect
like so:
res.redirect(303, "/forum");
This redirects for "Undefined Reason" which will default to a GET redirect.
See this SO post for more info.
I got it working on my Angular side with $window.location.href = '/forum';
- just put it in the success function of the $http
request that is part of the delete
function that gets executed when the "Delete" button is clicked.