【发布时间】:2019-05-07 05:04:34
【问题描述】:
我在将对象从 React 传递到 Express,然后在 Express 中创建可播放记录时遇到问题。
在反应中,我通过以下方式向 Express 发送 http 请求:
finalSubmit() {
const airtableObj = {
title: 'hi',
}
fetch('api/submit',{
method: 'POST',
body: JSON.stringify(airtableObj),
headers: {"Content-Type": "application/json"}
})
}
我的快递代码是:
app.post('/api/submit', jsonParser, async (req, res) => {
const newStudy = JSON.stringify(req.body);
await console.log(newStudy);
table.create(newStudy, function(err, record) {
if (err) {console.log(err); res.json(err)} else {console.log(record), res.json('Success!')}
});
})
但是,我不断从 airtable api 收到错误消息。如果我将我的快速代码的第 4 行替换为:
table.create({“title”:“hi”}
而不是
table.create(newStudy)
,一切正常。似乎这应该根据空气表文档工作......(https://airtable.com/api)。我在处理数据进出 JSON 的方式上做错了什么吗? 谢谢
【问题讨论】: