Is there a way to add additional data to a formdata element that handles a file upload? I know formdata doesn't support .push()?
$("frm").submit(function (e) {
e.preventDefault();
var data = new FormData($(this)[0]);
});
If I'm understanding your question correctly, you want to add extra keys and values to the FormData object after taking them from the form. If so, yes you can! It uses the append
method:
data.append('SomeField', 'SomeValue');
You can do this with a string, or with a Blob
or File
object as suits you.
This is documented in the MDN page for FormData
.
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