Skip to content

Instantly share code, notes, and snippets.

@Marian0
Created March 4, 2015 14:42
Show Gist options
  • Save Marian0/069dc670f4f35dbab501 to your computer and use it in GitHub Desktop.
Save Marian0/069dc670f4f35dbab501 to your computer and use it in GitHub Desktop.
Capturar submit y hacer un ajax como la gente
$(document).on('submit', '#contact' , function(event) {
url = $(this).attr("action");
console.log(url);
$.ajax({
type: "POST",
url: url,
datatype: "json",
data: {
"name": $("#contact #name").val(),
"email": $("#contact #email").val(),
"subject": $("#contact #subject").val(),
"message": $("#contact #message").val()
},
success: function(data) {
var obj = $.parseJSON(data);
if (obj.sendstatus === 1) {
$("#contactSuccess").removeClass("hide").addClass("show animated bounceIn");
$("#contactError").addClass("hide").removeClass("show animated bounceIn");
} else {
$("#contactError").removeClass("hide").addClass("show animated bounceIn");
$("#contactSuccess").addClass("hide").removeClass("show animated bounceIn");
}
},
complete: function() {
// Reset Form
$("#contact")
.find('.field')
.removeClass("success")
.removeClass("error")
.find("input")
.val("");
}
});
event.preventDefault();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment