首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法正确发布到php服务器- React Native

无法正确发布到php服务器- React Native
EN

Stack Overflow用户
提问于 2019-11-29 00:43:59
回答 1查看 50关注 0票数 0

我有问题张贴数据到php服务器。以下是我的代码的快照。有时工作和开机自检成功,有时不成功。

代码语言:javascript
复制
    < 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 >

这是响应的日志

代码语言:javascript
复制
{"_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"}

我能做错什么呢?

EN

回答 1

Stack Overflow用户

发布于 2019-12-03 17:42:22

我可以通过更改应用程序上的日期格式来解决这个问题。

我使用的是react-native-datepicker,而日期格式与服务器预期的不同。

代码语言:javascript
复制
    <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 }); }}
                />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59093300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档