问题描述
我有多部分内容 Web API。工作正常。并在邮递员中进行了测试。 现在我正在尝试使用 ajax post 方法在我的 asp.net web 应用程序中使用该 web api。我在谷歌中提到了一些编码并申请了。但它最终显示错误。我不知道我在做什么错误。我正在使用 .Net Framework 4.5。我的 api 编码和邮递员执行如下。
var data = new FormData();
jQuery.each(jQuery('#fileupload')[0].files,function (i,file) {
data.append('file',file);
});
data.append('siteCode','HQ');
data.append('phoneNumber','95878784XXX');
data.append('customerCode','C001');
data.append('notificationFlag','1');
$.ajax({
type: 'POST',url: SequoiaUri + "api/profilePicture",contentType: "application/json; charset=utf-8",data: data,dataType: "json",Cache: false,processData: false,success: function (data) {
alert("Picture Uploaded Successfully!");
}
解决方法
试试这个:
$.ajax({
url: SequoiaUri + "/api/profilePicture",data: data,type: 'POST',//enctype: 'multipart/form-data',// try if still is not working
contentType: false,processData: false,success: function (data) {
alert("Picture Uploaded Successfully!");
},.....