Jquery: Push FormData?

两盒软妹~` 提交于 2019-12-10 14:39:46

问题


Is there a way to add additional data to a formdata element that handles a file upload? I know formdata doesn't support .push()?

$("frm").submit(function (e) {
 e.preventDefault();
 var data = new FormData($(this)[0]);

 });

回答1:


If I'm understanding your question correctly, you want to add extra keys and values to the FormData object after taking them from the form. If so, yes you can! It uses the append method:

data.append('SomeField', 'SomeValue');

You can do this with a string, or with a Blob or File object as suits you.

This is documented in the MDN page for FormData.



来源:https://stackoverflow.com/questions/23876561/jquery-push-formdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!