jQuery(document).on('submit','#formlg',function(event){ event.preventDefault(); jQuery.ajax({ url: 'login.php', type: 'POST', dataType: 'json', data: $(this).serialize(), beforeSend: function() { $('.botonlg').val('Validando...'); } }) .done(function (respuesta) { console.log(respuesta); if (!respuesta.error){ if (respuesta.perfil == 'Jefatura') { location.href = 'sitio/admin/admin.php'; } else if (respuesta.perfil == 'Area') { console.log("Area"); location.href = 'sitio/usuario/usuario.php'; } } else{ $('.error').slideDown('slow'); setTimeout(function () { $('.error').slideUp('slow') },3000); $('.botonlg').val('Iniciar Sesion'); } }) .fail(function (resp) { console.log(resp.responseText); }) .always(function(){ console.log("complete"); }); });