The purpose of this action is to send data in JSON format using fetch under React. It works perfectly on desktop browsers, but not on those of the iPad (Chrome 63.0.3239.73). The action is to fill out a form, click on the Submit button, then call the setRedirect function and the code below is executed. Even after looking for hours, I can not find solutions ...
I was able to see that some bugs were due to the fact that iOS only allows https connections, I corrected it, but still not ...
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)
})
}
}
This code works on desktop browsers, without error, but on Chrome iPad, once you click on the button (input submit), nothing happens and nothing is sent. If you need additional information, I'm here.
Aucun commentaire:
Enregistrer un commentaire