Skip to content

Instantly share code, notes, and snippets.

@solancer
Created October 20, 2017 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solancer/ed12ea42cbb14b57ebd0bc6bae69359e to your computer and use it in GitHub Desktop.
Save solancer/ed12ea42cbb14b57ebd0bc6bae69359e to your computer and use it in GitHub Desktop.
jQuery Ajax Form With FIle Attachement
<script>
jQuery(document).ready(function() {
jQuery("#proform").submit(function(e) {
e.preventDefault();
var o = jQuery(this).serializeArray(),
t = jQuery(this).attr("action"),
i = jQuery("#formResponse"),
n = jQuery("#cfsubmit"),
form_data = new FormData(jQuery('#proform')[0]);
n.text();
return n.text("Sending..."), jQuery.ajax({
url: t,
type: "POST",
processData: false,
contentType: false,
async: false,
cache: false,
data : form_data,
success: function(e) {
i.html(e), n.fadeOut(200), jQuery("#proform").each(function() {
this.reset();
})
},
error: function(e) {
alert("Error occurd! Please try again")
}
}), !1
})
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment