I have to append some information in my JS with form data. Something like..
var form_data = new FormData();
form_data.append('photo', photo_data );
form_data.append('customer_id', customer_id);
form_data.append('year_name', year_name);
As we can see I have used .append thrice for three information. I tried something like this and did not work as .append() expects two parameters(field name and value) and not object.
var data = {'photo': photo_data, 'customer_id': customer_id, 'year_name', year_name};
form_data.append(data);
I wish to know if there is some way to pass multiple field names and values in a single line. Thanks!
formdataand then you start usingform_data?<form>, you can directly callnew FormData(yourForm)Object.keys(data).forEach(function(k){form_data.append(k, data[k]);})