【发布时间】:2019-12-03 17:42:22
【问题描述】:
我在将数据发布到 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"}
请问我做错了什么?
【问题讨论】:
-
到底是什么问题?您如何在 PHP 中检索数据?您发送什么以及您实际期望什么响应? “有时有效,有时无效” 并没有真正让我们继续下去。请记住,我们不知道您的应用程序应该做什么或它是如何工作的。
-
响应是 500(内部服务器错误),所以这可能是后端的问题,你应该检查你的 php/webserver 日志
-
@MagnusEriksson,我无法成功发布到我的数据库,我的代码有问题。每当用户填写我的表单并单击我的按钮时,我都想将数据保存到我的数据库中。我可以使用邮递员成功发布,但我的代码不起作用
-
@bug,我可以使用邮递员成功发布,但我的代码不起作用
-
做一些适当的调试。当您发布数据时,检查开发者控制台中的网络选项卡以查看响应发送的数据和服务器返回的数据。如果您收到状态 500(如发布的响应所示),请检查服务器错误日志以找到真正的错误消息。目前,没有更多信息无法回答这个问题。
标签: php reactjs react-native post react-native-android