$(document).ready(function () { //$(".ajax_login").on('submit', function () { $(document).on('submit', ".ajax_login", function () { // Vamos a enviar los datos de login y esperar respuesta $.ajax({ type: 'POST', url: HTTP_CONTROLADOR + 'clientes.php', data: $(this).serialize() // serializes the form's elements. }) .done(function (msg) { if (msg) { reply = jQuery.parseJSON(msg); // Si hay algun aviso... if (reply.mensaje != '') { alert(reply.mensaje); } if (reply.status == 'ok') { // Login ok, recargamos la pagina if (reply.redirect) { location.replace(reply.redirect); } else { location.reload(); } } else { // Procesamos el error if (reply.redirect) { location.replace(reply.redirect); } } } else { alert(TXT_ERROR_PETICION); } }); return false; }); });