Created
October 20, 2017 22:52
-
-
Save solancer/ed12ea42cbb14b57ebd0bc6bae69359e to your computer and use it in GitHub Desktop.
jQuery Ajax Form With FIle Attachement
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
<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