This question might be very simple thing. But I couldnt figurout the issue in my code.
I want to send data to a node js api using jquery ajax call.
This is my node js API
.post('/createPerson', global.bodyParserJson, function (req, res, next) {
console.log(req.body);
// My code going here
})
This my ajax call from client side.
$.ajax({
type: 'post',
url: serverLocation + "/api/dashboard/createPerson",
dataType: 'json',
data: { Name: "John", Age: 20 },
contentType: "application/json; charset=UTF-8",
success: function (data) {
console.log('Sucss');
},
error: function (textStatus, errorThrown) {
console.log('Err');
}
});
API is hit by ajax call, but data is not passing. It comes as empty. I try to call the api using postman and it works well which means json data comes to server side.
Can you give me a clue to find the issue in my code?