Friday 24 April 2020

req.body return no data on XHR form submit

I'm trying to make XHR post request to my node app but req.body isn't returning anything.Frontend code: ``` ```Backend code: app.post('/admin/post/new',(req,res) => { let t = req.body.title; console.log(t) // returns: undefined console.log(req.body) // returns: {} console.log(req.method) // returns: POST res.send('Saved'); }body-parse: app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: true }))But if I do normal POST request without XHR or fetch then form is submitted properly.

Submitted April 24, 2020 at 07:38AM by pverma8172

No comments:

Post a Comment