【发布时间】:2017-02-19 10:33:22
【问题描述】:
我是 Node 新手,我正在尝试使用 app.post,一切正常,包括执行操作时的控制台日志,但它没有接收到来自 main.js 的 AJAX 发送的数据。
这是发送它的 main.js 的一个sniper:
$.ajax({
type: 'POST',
data: '{"title":'+ this.messageInput.value +'}',
url: 'http://localhost:3000/send'
});
这是我应该接收数据的 config.js:
app.post('/send', function(req, res) {
console.log(req.body);
console.log('Send button clicked');
});
我正在使用带有 express 的 bodyParser。这就是我使用 req.body 的原因。当我控制台日志 req.body 我得到未定义。当我控制台 log req 时,我得到一个数据列表,但不是我发送的内容。
希望有人能帮忙!
【问题讨论】:
标签: javascript jquery ajax node.js express