Originally, my routes would redirect the user to the page they submitted the request. However, this sends them back to the top of the page.
I implemented AJAX to submit the request, but what do I write in the route? I was originally using res.redirect, but switched wherever it said res.redirect
to return
, thinking that that would work, however my page just gets stuck in a process and after a minute or so, the page errors.
What is the correct way to process a request and then just stop?
How come return
doesn't work?
Use them together like this:
function(req, res, next) {
if (/*<case when you need redirect>*/) {
return res.redirect('/path/to/redirect');
} else if (/*<case when you need simple response>*/) {
return res.send();
}
// some other code here
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.