0
I have the following code:
jQuery('#modal').on('submit', function(e) {
jQuery('button[type="submit"]').prop('disabled', false);
jQuery('div[name="loading"]').html("<i class='fa fa-circle-o-notch fa-spin'></i> Processando...");
e.preventDefault();
setTimeout(function(){ ajax(); }, 10000);
jQuery('div[name="loading"]').html("");
jQuery('button[type="submit"]').prop('disabled', true);
});
function ajax() {
var data = jQuery('#form').serializeArray();
jQuery.ajax({
url: "url",
type: "POST",
data: data,
async: false,
success: function(returnjson) {
},
error: function(returnjson) {
}
});
}
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
<span><a href="" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#modal">Alterar informações pessoais</a></span>
<div class="modal" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel">Alterar Informações pessoais</h4>
</div>
<form class="form-horizontal" id="form" action="#">
<div class="modal-body">
<fieldset>
<div class="form-group">
<div class="col-md-12">
<input id="nome" name="nome" placeholder="Nome" required type="text" class="form-control input-md">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="cep" name="cep" placeholder="Cep" required type="text" class="form-control input-md">
</div>
</div>
<div class="col-md-12" name="loading" id="loading"></div>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
<button type="submit" class="btn btn-primary" name="submit" id="submit">Salvar alterações</button>
</div>
</form>
</div>
</div>
</div>
I need as soon as the customer clicks the send button, lock the button submit
of form
and await a response from ajax
.