Skip to content

Instantly share code, notes, and snippets.

@solancer
Created September 30, 2017 20:52
Show Gist options
  • Select an option

  • Save solancer/4832b34730faf72fe44b91a16c1349cb to your computer and use it in GitHub Desktop.

Select an option

Save solancer/4832b34730faf72fe44b91a16c1349cb to your computer and use it in GitHub Desktop.
Generic contact form AJAX function
$(document).ready(function() {
$("#contactForm").submit(function(e) {
e.preventDefault();
var o = $(this).serializeArray(),
t = $(this).attr("action"),
i = $("#contactFormResponse"),
n = $("#cfsubmit");
n.text();
return n.text("Sending..."), $.ajax({
url: t,
type: "POST",
data: o,
success: function(e) {
i.html(e), n.fadeOut(1e3), $("#contactForm").each(function() {
this.reset().fadeOut(1e3)
})
},
error: function(e) {
alert("Error occurd! Please try again")
}
}), !1
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment