Skip to content

Instantly share code, notes, and snippets.

@bwonur
Forked from oswaldoacauan/gist:7580474
Created January 27, 2020 13:13
Show Gist options
  • Save bwonur/8f78b78a9108ffca42a5d7494f12236e to your computer and use it in GitHub Desktop.
Save bwonur/8f78b78a9108ffca42a5d7494f12236e to your computer and use it in GitHub Desktop.
jQuery - Serialize Form with File inputs
(function($) {
$.fn.serializeFiles = function() {
var form = $(this),
formData = new FormData()
formParams = form.serializeArray();
$.each(form.find('input[type="file"]'), function(i, tag) {
$.each($(tag)[0].files, function(i, file) {
formData.append(tag.name, file);
});
});
$.each(formParams, function(i, val) {
formData.append(val.name, val.value);
});
return formData;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment