On form submission I'm using jQuery to gather data including files and creating a FormData Object of the form values using:
var formData = new FormData($("form#formid")[0]);
but how can I add another value and it's key to this FormData Object?
You can also use FormData.set().
The difference between FormData.set and append() is that if the specified key already exists, FormData.set will overwrite all existing values with the new one, whereas append() will append the new value onto the end of the existing set of values.
Syntax:
formData.set(name, value);
var data = new FormData(),
fields = $("#myForm").serializeArray();
$.each( fields, function( i, field ) {
data.append(field.name, field.value);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With