web前端 ajax请求上传图片数据类型处理

时间:2021-12-16 16:10:46
form: function (url, paras, files, success) {
//上传的文件类型是MultipartFile[]
//如果把需要的参数直接传入,则会请求错误
//设置请求参数的数据类型
var urlStr = UrlParas(url, paras).url;
console.log(urlStr)
var formData = new FormData();
for (var item in paras) {
formData.append(item, paras[item]);
} for (var item in files) {
for (var i = ; i < files[item].length; i++) {
formData.append(item, files[item][i]);
}
}
console.log(formData)
return;
$.ajax({
url: urlStr,
data: formData,
type: 'post',
contentType: false,
processData: false,
success: success,
error: function (msg) {
errorState(msg);
}
});
}