问题
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]);
});
回答1:
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.
来源:https://stackoverflow.com/questions/23876561/jquery-push-formdata