So I make a request:

$.ajax({ url: 'blabla/saveData/', type: 'POST', contentType: 'application/json', data: data, success: function(){ alert('Save success'); }, error: function(data) { console.error(data); } }); 

So in the route I'm trying to accept the request:

 router.post("/blabla/saveData", function(req, res) ... 

As a result, I get 500 Internal Server Error. How to parse such a request? In express, is there anything for this or do you need to catch the request yourself?

    1 answer 1

    https://github.com/expressjs/body-parser does it

    Example

     var express = require('express') var bodyParser = require('body-parser') var app = express() // parse application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: false })) // parse application/json app.use(bodyParser.json()) app.post('/blabla/saveData', function (req, res) { //req.body ... }) 
    • I use it, the same parameters are not working - sanu0074