ios - 在 React 中,我的 POST 获取请求在桌面上有效,但在 Chrome 上的 iPad 上无效,出了什么问题?

标签 ios reactjs web post fetch

此操作的目的是在 React 下使用 fetch 发送 JSON 格式的数据。它可以在桌面浏览器上完美运行,但不能在 iPad 浏览器上运行(Chrome 63.0.3239.73)。 该操作是填写表单,单击“提交”按钮,然后调用 setRedirect 函数并执行下面的代码。 即使寻找了几个小时,我也找不到解决方案......

我发现一些错误是由于 iOS 只允许 https 连接造成的,我纠正了它,但仍然没有......

setRedirect = (e) => {
        e.preventDefault();
        const jsonFile = JSON.stringify(
            {
                birthday: this.state.birthday, 
                country: this.state.country,
                email: this.state.email,
                firstname: this.state.firstname,
                lastname: this.state.lastname,
                newsletter: this.state.newsletter,
                offers: this.state.offers,
                phone: this.state.phone,
                screenSize: window.innerWidth,
                zipCode: this.state.zipCode
            }
        )
    console.log(jsonFile)
            if(window.fetch) {
                fetch("https://url.fr/event/player/save/",{
                    credentials: 'include',
                    headers: {
                        'Accept': 'application/json',
                        'Content-Type': 'application/json'
                    },
                    method: "POST",
                    body: jsonFile
                })
                .then(response => response.json())
                .then((jsonData) => {
                    console.log("reponse serveur",jsonData);
                    this.setState({
                        step: jsonData.code
                    })
                    localStorage.setItem("step",jsonData.code);
                    console.log("step local storage : ",localStorage.getItem("step"));
                    alert('response : '+jsonData);
                })
                .catch((error) => {
                    // handle your errors here
                    console.error(error)
                })
            }
    }

此代码适用于桌面浏览器,没有错误,但在 Chrome iPad 上,一旦单击按钮(输入提交),就不会发生任何事情,也不会发送任何内容。 如果您需要更多信息,我就在这里。

最佳答案

native 获取仅支持 iOS 10.3 或更高版本。在较旧的设备上,可以使用像这样的 polyfill 来使用 fetch:https://github.com/github/fetch

关于ios - 在 React 中,我的 POST 获取请求在桌面上有效,但在 Chrome 上的 iPad 上无效,出了什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56184128/

相关文章:

ios - 显示 ModalViewController 并进入后台状态后应用程序崩溃

ios - iBeacon 为多个信标发送通知

reactjs - 如何在 ReactJS webapp 中渲染格式化文本?

javascript - Stripe Payment 仅适用于我的 LocalHost,但不适用于 Heroku 服务器

android - Android/iOS 应用程序未检测到由 iOS/Android 应用程序索引的人脸 - AWS Rekognition

ios - UIToolbar - 添加无间隙的等宽按钮

reactjs - 嵌套的 ReactTransitionGroups componentWillLeaves 不会被触发

ReactJS - 具有多个输入的自动保存 - 最佳实践

web - 如何在 es6 中缓存 bust 导入的模块?

eclipse - 在eclipse中保存html文件没有效果