Im trying to just stop the post request after I’ve saved a document to the DB, ie:
//my code does a bunch of stuff
res.what do i put here to tell the client browser to just... stop the POST
At the moment im simply using
res.redirect('back') which works, but the page refresh is totally arbitrary and i would prefer it didnt happen. I had a go at
res.end(); but that sends the client to a blank page...
Thanks in advance.
I dont think i made myself clear enough in what im doing sorry.
Perhaps its bad practice but this is whats happening:
- POST initiates database save function
- Browser sits around waiting for a response
- When its good and ready, the obj is saved to the DB, then a callback triggers a NowJS function, which adds the item to the view(for everyone)
I did it this way to be non-blocking( so i thought)
Problem courtesy of: Andrew Plummer
You can use
res.end and pass in a string that you want to be sent to the client:
Alternatively, you could render a view and then end the response:
All that said, redirecting the client is actually the best practice. It makes it so that when they hit the back button in their browser, they can move back seamlessly without getting any “POST required” popups or the like. This is the POST/redirect pattern and you can read more about it at http://en.wikipedia.org/wiki/Post/Redirect/Get.
Solution courtesy of: Rohan Singh