转载:https://segmentfault.com/a/1190000012327982?utm_source=tag-newest
function uploadFile() {
var formData = new FormData();
formData.append("upload", $("#FileInput")[0].files);
console.log(formData);
$.ajax({
url: "https://www.easy-mock.com/mock/5be1484beeee54220716c03c/manage/uploadFile",
type: "POST",
data: formData, // 上传formData封装的数据
cache: false, // 不缓存
processData: false, // jQuery不要去处理发送的数据
// contentType: false, // jQuery不要去设置Content-Type请求头
contentType: 'text/xml', // 设置Content-Type请求头
success: function(res) {
console.log("success");
}
});
}