Skip to content

Instantly share code, notes, and snippets.

@AmitKKhanchandani
Created October 18, 2018 09:53
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 AmitKKhanchandani/74c9389239af3fbed141465f3814d60a to your computer and use it in GitHub Desktop.
Save AmitKKhanchandani/74c9389239af3fbed141465f3814d60a to your computer and use it in GitHub Desktop.
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