【发布时间】:2020-12-23 10:47:41
【问题描述】:
来自 Express response.send 的文档允许在正文中发送对象,我发送如下:
DBM.saveArticle(obj).then((val) => {
console.log(val); // verified here
res.send(val);
res.end();
// ... clip here
但是在客户端我没有得到对象。这是在 CRUD 中创建的,我正在使用 fetch POST 来实现这一点。
// ... snip
const options = {
headers: {'Content-Type': 'application/json'},
method: 'POST',
body: JSON.stringify(this.state)
};
fetch("/articles/add", options)
.then((response) => {
console.log('DEBUG: Article Added: ', response); // nothing found here in response
this.props.dispatch({type: 'addArticle', component_state: state});
})
.catch((error) => {
console.log('fetch/POST error', error);
});
// ... snip
上面的console.log看起来像这样,这是一张图片,据我所知,它是空的。
响应对象很大,我试图点击它的所有内容,但我可能错过了一些东西。
JavaScript 获取响应对象的官方文档是here on MDN。
【问题讨论】:
标签: javascript reactjs express fetch