Created
October 18, 2018 09:53
-
-
Save AmitKKhanchandani/74c9389239af3fbed141465f3814d60a to your computer and use it in GitHub Desktop.
FormData Example with File from the input element
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
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