Last active
December 10, 2015 10:08
-
-
Save sjimenez77/4419432 to your computer and use it in GitHub Desktop.
jQuery: jQuery Mobile: Valiadación y llamada AJAX para enviar un correo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Validación y llamada AJAX para enviar el correo */ | |
$("#submit").click(function() { | |
var nombre = $("#nombre").val(); | |
email = $.trim($("#email").val()); | |
validacion_email = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/; | |
asunto = $("#asunto").val(); | |
mensaje = $("#mensaje").val(); | |
if ((nombre == "") || (nombre == $("#nombre").attr('placeholder'))){ | |
$( "#nombre_error" ).popup( "open" ); | |
return false; | |
} else if(email == "" || (email == $("#email").attr('placeholder')) || !validacion_email.test(email)){ | |
if (!validacion_email.test(email)) | |
$( "#email_error" ).popup( "open" ); | |
else | |
$( "#email_vacio" ).popup( "open" ); | |
return false; | |
} else if(asunto == "" || (asunto == $("#asunto").attr('placeholder'))){ | |
$( "#asunto_error" ).popup( "open" ); | |
return false; | |
} else if(mensaje == ""){ | |
$( "#mensaje_error" ).popup( "open" ); | |
return false; | |
} else { | |
// Si todo paso, aqui ira la llamada AJAX | |
var datos = 'nombre='+ nombre + '&email=' + email + '&asunto=' + asunto + '&mensaje=' + mensaje; | |
$.ajax({ | |
type: "POST", | |
url: "../proceso.php", | |
data: datos, | |
success: function() { | |
$( "#mensaje_enviado" ).popup( "open" ); | |
}, | |
error: function() { | |
$( "#mensaje_no_enviado" ).popup( "open" ); | |
} | |
}); | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment