Created
November 21, 2013 12:06
-
-
Save oswaldoacauan/7580474 to your computer and use it in GitHub Desktop.
jQuery - Serialize Form with File inputs
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
(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); |
semi-colon missed in line 4
not a semicolon, but a comma solves.
Be sure to use a comma on line 4, not a semicolon, otherwise formParams will be declared in the global variable space.
Very helpful !!!
it's very good idea
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
semi-colon missed in line 4