I simply make a ajax call to certain method in nodeJs app, and expected to log all parameters to see pass data properly. but since I post this its not..
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
// set the port of our application
var port = process.env.PORT || 8080;
app.set('view engine', 'ejs');
// make express look in the public directory for assets (css/js/img)
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.get('/', function(req, res) {
// ejs render automatically looks in the views folder
res.render('index');
});
app.listen(port, function() {
console.log('Our app is running on http://localhost:' + port);
});
'use strict';
app.post('/sendMail', function(request, response) {
console.log(request.body)//returns {} but why its empty?
})
and here is ajax call;(I validate paramters exist in headers via dev console)
constructor() {
this.message={
email:"",
message:""
}
}
@action postData() {
$.ajax({
url:"http://localhost:8080/sendMail",
ContentType:'application/json',
dataType:'json',
type:'post',
data:{body:this.message},
success:(result) =>{
},
EDITED: I am able to see data in log if I make a post request via POSTMAN I choose content-type:application/json and added raw json string "{'message':'hello world'}" and I saw in nodejs log its passed successfully whats wrong with my ajax call here ?