【发布时间】:2018-02-20 10:47:48
【问题描述】:
我正在编写一个具有“注册”功能的程序。前端是使用 React.JS 创建的。到目前为止,我可以使用此代码在 React.JS 中发送发布请求:
fetch('http://localhost:2000/users/signup/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"email": "testing@gmail.com",
"password": "secret",
"name": "matthew",
"organization": "Apple"
})
}).then(function(response) {
return response.json();
});
这非常有效 - 因为用户信息现在在数据库中。但是我不确定如何使用 response.json() 获取响应 JSON。我希望能够接受响应,获取消息字符串,并在前端将其显示给我的用户。这是我在 Postman 上运行相同的 post 请求时的响应。
{
"message": "New user created"
}
感谢您的帮助!
【问题讨论】:
-
你已经有了 json...它是
response.json()你应该可以通过控制台记录它...
标签: mongodb reactjs http-post fetch postman