ajax调用不能传递参数给nodejs应用程序

我通过下面的代码进行ajax调用,期望看到参数通过nodejs应用程序,但它总是空的

@action postData() { $.ajax({ url:"http://localhost:8080/sendMail", ContentType:'application/json', dataType:'json', type:'post', data:JSON.stringify({'message':'helloworld'}), success:(result) =>{ .. }) 

如果我在postman中发送一个post请求(把原始stringjson参数添加到body; {'message':'helloworld'}),它传递的很好,我看到它的日志logging。 那么这个ajax调用什么错误,我在reactjsapp中使用?

编辑:它看起来在浏览器中传递的所有参数,但不知何故nodejs无法让他们.. 在这里输入图像说明

由于POST数据是在HTTP正文中发送的,因此您需要parsingJSON以获取它。 假设你在服务器端使用express.js,你可以使用body-parser来做到这一点:

 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())