Created
March 4, 2015 14:42
-
-
Save Marian0/069dc670f4f35dbab501 to your computer and use it in GitHub Desktop.
Capturar submit y hacer un ajax como la gente
This file contains 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
$(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