I have this api with fetch that is taking the data of a form, with the formdata object optengo the data of said form built in html, then they are sent to the server, a php file that processes the data sent from javascript, in php the data are stored in a database and sends a response to the client, the problem I have is that in local I have tried and everything goes great, but when I go to a paid hosting to try my application optengo a
let formulario = document.getElementById('formulario');
formulario.addEventListener('submit', function (e) {
e.preventDefault();
const datos = new FormData(formulario);
fetch('./includes/add.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
mode: 'cors',
body: datos
})
.then(res => res.json())
.then(data => {
console.log(data);
if (data == 'respuesta') {
Swal.fire({
icon: 'success',
title: 'mensaje enviado',
showConfirmButton: true,
timer: 1500
})
formulario.reset();
} else if (data == "error") {
Swal.fire({
icon: 'error',
title: 'mensaje no enviado',
showConfirmButton: true,
timer: 1500
})
formulario.reset()
}
})
})
let formulario = document.getElementById('formulario');
formulario.addEventListener('submit', function (e) {
e.preventDefault();
const datos = new FormData(formulario);
fetch('./includes/add.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
mode: 'cors',
body: datos
})
.then(res => res.json())
.then(data => {
console.log(data);
if (data == 'respuesta') {
Swal.fire({
icon: 'success',
title: 'mensaje enviado',
showConfirmButton: true,
timer: 1500
})
formulario.reset();
} else if (data == "error") {
Swal.fire({
icon: 'error',
title: 'mensaje no enviado',
showConfirmButton: true,
timer: 1500
})
formulario.reset()
}
})
})