【发布时间】:2020-04-13 09:46:46
【问题描述】:
我已经实现了一个外部 API 函数以在单击按钮时返回 text/html。但似乎没有返回数据。而是返回一个承诺。
<TouchableOpacity onPress={() => getData() }>
<Text style={styles.button}>Register</Text>
</TouchableOpacity>
获取函数
const getData= () => {
let formData = new FormData();
formData.append("name", 'ABC');
formData.append("age", 35)
fetch(API_URL, {
method: 'POST',
body: formData,
}).then(response => {
console.log('success');
console.log(JSON.stringify(response.text()))
}).catch(error => {
console.log('error');
console.error(JSON.stringify(response));
})
}
我只想要 html/文本响应
【问题讨论】:
-
response.text()是一个承诺。 (a)等待它也被解决
标签: reactjs react-native fetch