【发布时间】:2020-11-07 15:32:32
【问题描述】:
我的端点将发送如下响应:
res.status(400).json({"note","this email is already taken"});
使用 React 我使用 axios 如下
export const signUpUser = (email, password) => {
const headers = {
"Content-Type": "text/plain",
};
return axios
.post(
https://domain.something + "/signup",
{ email, password },
{ headers ,}
)
.then((res) => {
return res;
})
.catch((err) => {
return err;
});
};
但是我无法通过 react 提取 JSON,这就是控制台日志显示的内容:
【问题讨论】:
-
创建 de 请求的反应代码是什么?问题似乎是响应抛出异常,因为它是 400 代码,您应该使用“catch”处理这些异常
-
也是
json({note:"this email is already taken"}) -
您如何检索数据? React 不附带数据访问库。
-
这种情况下我用的是axios
-
@prabhu 正确的代码是按照你写的那样写的。
标签: javascript json reactjs axios postman