gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:45:31 24 4
gpt4 key购买 nike

此操作的目的是在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com