我在将数据发布到php服务器时遇到问题。 这是我的代码的快照。 有时它可以正常工作并成功发布,有时却不成功。
< TouchableOpacity
style = {{ fontSize: 18, color: 'white' }}
containerStyle = {{
padding: 8,
marginLeft: 70,
marginRight: 70,
height: 40,
borderRadius: 6,
backgroundColor: 'mediumseagreen'
}}
onPress = {() => {
if (this.state.newTodo == "") {
alert("Please enter a reason for appointment");
return false
}
var query = {
Reason: this.state.newTodo,
BranchRef: this.props.branch,
AppointmentDate: this.props.date,
ToSeeRef: 369,
PatientRef: 63,
AppointmentTimeID: this.props.appointmentTime,
AppointmentPlatform: 2,
Completed: 0
}
console.log(query)
return fetch('url', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(query)
})
// .then((response) => console.log(response))
.then((response) => response.text())
.then((text) => {
if (Platform.OS === 'android') {
text = text.replace(/\r?\n/g, '').replace(/[\u0080-\uFFFF]/g, ''); // If android , I've removed unwanted chars.
}
return text
})
}}
>
<View style={styles.submitButton}>
<Text style={styles.submitButtonText}>BOOK APPOINTMENT</Text>
</View>
</TouchableOpacity >
这是响应的日志
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "f90a0dc3-02be-45e6-a600-41a2cc53a9e8", "offset": 0, "size": 89967}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": "f90a0dc3-02be-45e6-a600-41a2cc53a9e8", "offset": 0, "size": 89967}}, "headers": {"map": {"cache-control": "no-cache, private", "content-length": "89967", "content-type": "text/html; charset=UTF-8", "date": "Thu, 28 Nov 2019 16:35:23 GMT", "phpdebugbar-id": "fcebec1aec584329cabe4020a9122113", "server": "Microsoft-IIS/8.5", "x-powered-by": "ASP.NET", "x-ratelimit-limit": "60", "x-ratelimit-remaining": "59"}}, "ok": false, "status": 500, "statusText": undefined, "type": "default", "url": "https://visioncapital.officemate.ng/api/store_appointment"}
请问我该怎么做?
答案 0 :(得分:0)
我能够通过更改应用程序上的日期格式来解决此问题。
我正在使用react-native-datepicker,并且日期格式与服务器期望的日期格式不同。
<DatePicker
date={this.state.date}
mode="date"
format="YYYY-MM-DD"
confirmBtnText="Confirm"
cancelBtnText="Cancel"
customStyles={{
dateIcon: {
position: 'absolute',
left: 0,
top: 4,
marginLeft: 0
},
dateInput: {
marginLeft: 36,
borderWidth: 0,
right: 0,
color: "grey"
}
}}
onDateChange={(date) => { this.setState({ date:
date }); }}
/>