【发布时间】:2017-10-30 14:46:09
【问题描述】:
好的,所以我觉得这比它需要的要微不足道,但由于某种原因,当它传递给 get 方法时,我无法从我的“身体”中获取信息。我尝试了许多不同的方法来访问它,但没有任何方法可以解决问题。指导非常感谢。以下是我的代码:
---------------fetch method----------------
var x = e.target.phone.value;
var y = e.target.email.value;
console.log(x); // proper output
console.log(y); // proper output
fetch('/api/insert',
{
accept: 'application/json',
body: {
phone2: x,
email2: y
}
});
------------get method--------------
app.get('/api/insert', (req, res) => {
const phone = req.body.phone2; <-- Am I accessing the data incorrectly?
const email = req.body.email2; <-- Am I accessing the data incorrectly?
console.log(phone); // getting undefined here... Why?
console.log(email); // and here...
});
});
【问题讨论】:
-
console.log(req)和console.log(res)的输出是什么?
标签: javascript node.js reactjs express