How to remove value from FormData

后端 未结 2 1204
栀梦
栀梦 2020-12-16 12:18

Here is a way to append file to FormData :

  var data = new FormData();
  jQuery.each($(\'#file\')[0].files, function(i, file) {
           


        
相关标签:
2条回答
  • 2020-12-16 12:27

    I know this thread is old but I just found this : https://developer.mozilla.org/en-US/docs/Web/API/FormData/delete

    I'm sur it could help. You can use formData.delete(name) to delete the entry of formData with "name" key.

    0 讨论(0)
  • 2020-12-16 12:35

    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]);
    }
    
    0 讨论(0)
提交回复
热议问题