Well, I do not know if my title is related to what I'm asking for, but I have a form with an Enter button.
<button id="btn_entrar" data-loading-text="carregando..." autocomplete="off" class="btn btn-primary btn-cons m-t-10" type="submit" onclick="return Get_Acesso();">Entrar</button>
And when I enter login and password I want this button to be "loading ..." I searched the internet and saw this case:
$('button[data-loading-text]').on('click', function () {
var btn = $(this)
btn.button('loading')
setInterval(function () {
btn.button('reset')
}, 3000)
});
But I do not want a definite time (in the case 3 seconds) I want it to reset after my function GetAcesso()
give some return is false or true. Does anyone know a solution?
function Get_Acesso(){
usuario = document.getElementById('txt_user_name').value;
senha = document.getElementById('txt_password').value;
LoginDTO.Usuario = usuario;
LoginDTO.Senha = senha;
var DTO = { 'LoginDTO': LoginDTO};
//acessar login
$.ajax({
type: "POST",
url: "default.aspx/Acesso_Login",
data: JSON.stringify(DTO),
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function () {
$('#btn_entrar').html('Carregando...');
},
success: function (msg) {
$('#btn_entrar').html('Entrar');
try {
//tratamentos de msg
if (msg.d == "err") {
document.getElementById('spn_retorno').innerHTML = "Erro inesperado no momento do acesso.";
return false;
//Não encontrou nenhum registro
} else if (msg.d == "not") {
document.getElementById('spn_retorno').innerHTML = "Usuário / senha inválido.";
return false;
//Campos vazios
}
Simple access code, but I want it to return when the error returns with the default "Enter" button.