【发布时间】:2019-02-27 10:39:33
【问题描述】:
我已经阅读了许多与我类似的问题,但没有一个能解决我的问题, 我的 fetch (Get Method) 工作正常,但 (POST METHOD) 显示 JSON 输入意外结束
fetch('http://monasabat-app.com/Queries/sub_cat.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: 3
}),
}).then((response) => response.json())
.then((responseJson) => {
this.setState({
fsubCategory: responseJson.sub_cat
})
})
.catch((error) => {
console.error(error);
});
}
这是我收到的 POSTMAN 回复
{
"sub_cat": [
{
"id": "4",
"sub_cat": "sbu1",
"img_path": "url"
},
{
"id": "9",
"sub_cat": "sub2",
"img_path": "url"
}
]
}
【问题讨论】:
标签: json react-native post fetch fetch-api