How to end an express.js / node POST response?

前端 未结 7 1637
情歌与酒
情歌与酒 2020-12-28 12:51

Im trying to just stop the post request after I\'ve saved a document to the DB, ie:

app.post(\'/blah\'), function(req,res){ 
//my code does a bunch of stuff
         


        
7条回答
  •  独厮守ぢ
    2020-12-28 13:09

    If you could modify your client side code to make the post request via AJAX, you could simply use res.end().

    The problem here is that when the browser makes a POST request (not via AJAX), it no longer cares about the current page. It is expecting a new page, so it will load a new page. This is purely with the browser, and I do not believe there is currently a way for you to work around it.

    Overall, you should just use an AJAX POST request if you can.

提交回复
热议问题