表单数据的不同元素的不同内容类型

时间:2022-11-26 23:55:20

I am unable to send content-type application/json with the first element of my form data.

我无法使用表单数据的第一个元素发送内容类型的application / json。

My code:

我的代码:

var fd = new FormData();
fd.append('addBank', JSON.stringify(reqData.addBank[0]));
fd.append('bankProof', reqData.bankProof);
var promise  = $http.post(url, fd, { transformRequest: angular.identity, headers: {'Content-Type': undefined}});

When I try to set the content-type for first key value pair, it makes the data blank in the request.

当我尝试为第一个键值对设置内容类型时,它会使请求中的数据为空。

1 个解决方案

#1


0  

You can set value appended to FormData object as a Blob with data set to JSON and type set to "application/json"

您可以将附加到FormData对象的值设置为Blob,并将数据设置为JSON,并将类型设置为“application / json”

fd.append("addBank"
, new Blob([JSON.stringify(reqData.addBank[0])], {type:"application/json"}));

#1


0  

You can set value appended to FormData object as a Blob with data set to JSON and type set to "application/json"

您可以将附加到FormData对象的值设置为Blob,并将数据设置为JSON,并将类型设置为“application / json”

fd.append("addBank"
, new Blob([JSON.stringify(reqData.addBank[0])], {type:"application/json"}));