How to combine two javascript FormData objects

醉酒当歌 提交于 2019-12-01 16:17:19

You cannot. FormData is unfortunately not enumerable.

However, as you say only one of your forms does contain a file input. Then it should be possible to use serializeArray on the other and append to the data manually:

var formData = new FormData(document.forms['form-ship']); // with the file input
var poData = jQuery(document.forms['po-form']).serializeArray();
for (var i=0; i<poData.length; i++)
    formData.append(poData[i].name, poData[i].value);

I did it this way:

let formData = new FormData($("#f_articulos")[0]);
let formDataPrecios = new FormData($("#f_listado_precios")[0]);
for (var pair of formDataPrecios.entries()) {
    formData.append(pair[0], pair[1]);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!