【发布时间】:2017-01-23 03:12:32
【问题描述】:
当我向快递发送 Ajax 请求时,我使用 req.body.email 捕获 json 数据 控制台中的输出给我 undefined....请帮助...
客户端
$.ajax({
url: '/getRandomPass',
dataType: "json",
data:{'emailId':'sampleemailiD@gmail.com'},
type: 'POST',
cache: false,
success: function(data) {
console.log("cleint recieved data",data);
// this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.log(xhr,status,err);
}.bind(this)
})
服务器端
app.use(bodyParser.json());
app.post('/getRandomPass', function(req, res) {
console.log("req",req.body.emailId);
});
【问题讨论】:
-
您是否设置了响应内容类型?
-
你的意思是
console.log("on success",data);打印html内容吗? -
@DustinToothless:我确实将内容类型设置为文本,例如 res.set('Content-Type','text')
标签: jquery node.js express body-parser