【发布时间】:2019-10-16 18:44:45
【问题描述】:
我正在尝试使用fetch 将一个简单的注册表单保存到服务器,但得到了false 的响应。
apiDataSave = () => {
fetch('<myapi>', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
name : "abc",
no : "1234567890",
password : "123",
email : "abc@gmail.com"
})
})
.then(function(response) {
return response.json();
})
.then(function(data) {
alert(`response json is: ${JSON.stringify(data)}`)
})
}
我收到如下警报:
响应json为:{"status":false,"data":[]}
预期结果警报是:
response json is: {"status":true,"data":"1"} // 输入数据库的记录数
【问题讨论】:
标签: react-native post fetch-api