Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove value from FormData

Tags:

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

like image 864
talkhabi Avatar asked Jan 29 '14 21:01

talkhabi


People also ask

How do I find my FormData value?

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.

How do I check if a FormData is empty?

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!

What is new FormData ()?

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 .

What is the use of FormData append?

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.


1 Answers

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]); } 
like image 181
Michael Dunlap Avatar answered Sep 20 '22 21:09

Michael Dunlap