我有这个
POST api http://myIP/api/confirm
张贴姓名,文本,service_name,office_name,日期,时间
并且我想用它在React native中发布此变量
按下botton上的发布这些变量并给我警报消息 我怎样才能做到这一点 这是我的反应本机代码
<View>
<Text> {this.props.navigation.state.params.name}- {this.props.navigation.state.params.text} </Text>
<Text> {this.props.navigation.state.params.service_name}</Text>
<Text>{this.props.navigation.state.params.office_name}</Text>
<Text>{this.props.navigation.state.params.date}</Text>
<Text{this.props.navigation.state.params.time} </Text>
<Button rounded
title='next'
onPress={() => {
Alert.alert('The Appointment booked') }} />
</View>
答案 0 :(得分:0)
您可以执行以下
fetch("http://myIP/api/confirm", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
firstParam: "yourValue",
secondParam: "yourOtherValue"
})
})
.then(response => response.json())
.then(responseJson => {
Alert.alert(
"Alert Title",
"My Alert Msg",
[
{
text: "Cancel",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
},
{ text: "OK", onPress: () => console.log("OK Pressed") }
],
{ cancelable: false }
);
})
.catch(error => {
console.error(error);
});
但是请从react-native导入警报