If you intend to send the form data, process and receive some feedback, then you must disable the button in beforeSend and after receiving the return in Success you must enable the button again, or you can redirect to another page. I believe the code below can help you.
jQuery(document).ready(function(){
jQuery("#send").click(function(event){
event.preventDefault();
codigo = jQuery('input[id="nome"]').val();//campo no form
jQuery.ajax({
url: 'teste_botao.php',
dataType: 'html',
data: {par01: codigo},
type: 'POST',
beforeSend: function(){
//jQuery('#insere-aqui').html(iconCarregando);
jQuery('#send').attr('disabled', 'disabled');//desabilito
},
complete: function(){
jQuery(iconCarregando).remove();
},
success: function(data, textStatus) {
jQuery('#insere-aqui').html('');
jQuery('#insere-aqui').html(data);
jQuery('#send').removeAttr('disabled');//habilito
},
error: function(xhr,er) {
jQuery('#insere-aqui').html('Error ' + xhr.status + ' - ' + xhr.statusText + '<br />Tipo de erro: ' + er +'')
}
});
});
});
EXAMPLE With serialize()
<script type="text/javascript">
$(document).ready(function(){
var iconCarregando = $('<img src="../icon/mini.gif" class="icon" /> <span class="destaque">Carregando. Por favor aguarde...</span>');
$('#form_um').submit(function(e) {
e.preventDefault();
var serializeDados = $('#form_um').serialize();
$.ajax({
url: 'exemplo-serialize.php',
dataType: 'html',
type: 'POST',
data: serializeDados,
beforeSend: function(){
$('#insere_aqui').html(iconCarregando);
$('#send').attr('disabled', 'disabled');//desabilito
},
complete: function() {
$(iconCarregando).remove();
},
success: function(data, textStatus) {
$('#insere_aqui').html('<p>' + data + '</p>');
$('#send').removeAttr('disabled');//habilito
},
error: function(xhr,er) {
$('#mensagem_erro').html('<p class="destaque">Error ' + xhr.status + ' - ' + xhr.statusText + '<br />Tipo de erro: ' + er +'</p>')
}
});
});
})
</script>
If you take this JS code Submit occurs? I ask this because I do not know what you put in your form action.
– Edgar Muniz Berlinck
yes, my form was already working , I am trying to solve the problem of the user being able to click several times
– Ilgner de Oliveira
deactivate the
$("#send")
at the eventsubmit
of their respectiveform
.– Tobias Mesquita
and so onsubmit="send.disabled=true;" ?
– Ilgner de Oliveira
added an answer with more information about the problem and the possible solution.
– Tobias Mesquita
http://answall.com/questions/86806/como-trata-que-a-submissive%C3%A3o-de-um-formul%C3%A1rio-se-execute-once-only/86807#86807
– David Schrammel
It did not work here the solution of this duplicate , not disabled
– Ilgner de Oliveira
I always do it the way you did, using true false with a variable. Just so you know, we’re not a forum. If you have an answer then post as answer, do not put the answer within the body of the question, this is very confusing. We are a Q&A ;)
– Guilherme Nascimento