-1
How can I prevent the user from doing multiple submissions of a form? My code is like this:
// VALIDAÇÃO DO CADASTRO
$(document).ready(function(e){
$(function () {
// VALIDAÇÃO
$("#frmCadastro").validate({
rules: {
IdUnicoop: {
required: true
}
},
messages: {
IdUnicoop: {
required: ""
}
},
// Do not change code below
errorPlacement: function (error, element) {
error.insertAfter(element.parent());
},
submitHandler: function (form) {
var form = $("#frmCadastro");
var formdata = false;
if (window.FormData){
formdata = new FormData(form[0]);
}
$.ajax({
type: 'POST',
url: 'pAddEstagio.php',
data: formdata ? formdata : form.serialize(),
dataType: 'json',
cache: false,
contentType: false,
processData: false,
beforeSend: function () {
// $("#msgResult").html('AVISO! Enviando...');
},
success: function (response) {
e.preventDefault();
if (response.codigo == "1") {
bootbox.alert({
message: response.mensagem,
callback: function () {
window.location.href = "iAddEstagio.php";
}
})
} else {
e.preventDefault();
bootbox.alert({
message: response.mensagem,
callback: function () {
window.location.href = "iAddEstagio.php";
}
})
}
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr, ajaxOptions, thrownError);
bootbox.alert({
message: "ATENÇÃO! Ocorreu um erro ao tentar enviar a solicitação. Contate o suporte técnico.",
})
// $("#msgResult").html('ATENÇÃO! Ocorreu um erro ao tentar enviar a solicitação. Contate o suporte técnico.');
}
});
return false;
}
});
});
});
I tried to use the preventDefault but without success.
Broad question. 1 - Disable Submit in Success. 2-make use of localStorage or sessionStorage ( will depend on what this double sending refers to whether during the session or not) to inhibit Submit.
– user60252