Here is a way to append
file to FormData
:
var data = new FormData(); jQuery.each($('#file')[0].files, function(i, file) { data.append('file-'+i, file); });
is it possible to do as below ?
data[i].remove();??? or data[i] = file;??
how iIcan remove or modify a value from data
The get() method of the FormData interface returns the first value associated with a given key from within a FormData object. If you expect multiple values and want all of them, use the getAll() method instead. Note: This method is available in Web Workers.
val(); if(name && pret){ $. ajax({ url: 'connect. php', type: 'POST', data: formData, async: false, cache: false, contentType: false, processData: false, success: function(){ alert('uploaded successuflly! '); } }); }else{alert('input fields cannot be left empty you num num!
let formData = new FormData([form]); If HTML form element is provided, it automatically captures its fields. The special thing about FormData is that network methods, such as fetch , can accept a FormData object as a body. It's encoded and sent out with Content-Type: multipart/form-data .
append() The append() method of the FormData interface appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist.
You cannot do anything other than append items to a FormData object. See the Spec. It would be better if you use a dictionary/object to store all the values you want to add/modify before you actually construct the object.
var data = {}; jQuery.each($('#file')[0].files, function(i, file) { data['file-'+i] = file; }); //modify the object however you want to here var formData = new FormData(); for (var key in data) { formData.append(key, data[key]); }
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