0
I made an ajax request to send the data from a form to the server, the data is sent and stored perfectly. But when processing the Success creating the condition, should the return of result were the standard 200 or "OK" would send a message of success and if not, the error message. However, in doing so I realized that the result was not returning because it already fell straight into Isis. And even dropping ELSE, it stores the data on the server, but throws the error message.
function showMessageError(message)
{
document.getElementById("errorMsg").innerHTML = message;
$("#divError").fadeIn(200).delay(2500).fadeOut(200);
}
>
function sendForm()
{
$("#divSucesso").hide();
$("#divError").hide();
document.getElementById("btnEnviarForm").disabled = true;
var formAgenda = document.getElementById("form");
var formData = new FormData (formAgenda);
$.ajax({
url: 'insert.php',
method: "POST",
data: formData,
cache: false,
processData: false,
contentType: false,
success: function (result) {
if (result.statusText == "OK")
{
document.getElementById("sucessoMsg").innerHTML = "Dados salvos com sucesso: " + result;
$("#divSucesso").stop().fadeIn(200).delay(2500).fadeOut(200);
document.getElementById("btnEnviarForm").disabled = false;
document.getElementById("form").reset();
}
else
showMessageError(result);
},
error: function (xhr, status, error) {
var errorMsg = xhr.responseText;
document.getElementById("errorMsg").innerHTML = errorMsg;
$("#divError").fadeIn(200).delay(2500).fadeOut(300);
document.getElementById("btnEnviarForm").disabled = false;
}
})
}
Gabriel, could you pass the error that is happening? So I have a parameter to investigate.
– Mateus Saggin
@Mateussaggin there that is expensive. He is not indicating what is the mistake, I am not understanding.
– Gabriel
@Mateussaggin, he’s kind of not getting into the IF, so don’t
– Gabriel
has some link running this script?
– Mateus Saggin
@Mateussaggin, I’ve rearranged my question, maybe it’s a little clearer. And in reply, I’m testing at WAMP locally.
– Gabriel
You could post the code of Insert.php?
– Paulo Sérgio Filho