Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: Push FormData?

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]);

 });
like image 720
Ralph Avatar asked May 26 '14 19:05

Ralph


1 Answers

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.

like image 106
lonesomeday Avatar answered Oct 19 '22 04:10

lonesomeday