Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FormData Example with File from the input element
var file = $('#order_file').prop('files')[0];
var form_data = new FormData();
form_data.append('order_file',file)
$.each($('#ordercreate').serializeArray(), function (key, input) {
if (form_data.has(input.name)) {
form_data.set(input.name, input.value);
} else {
form_data.append(input.name, input.value);
}
});
// console.log(form_data); // This will return an empty object, so dont worry!
for (var key of form_data.entries()) {
console.log(key[0] + ', ' + key[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment