jquery+ajax上传文件
// 简历UI
function fileUploadUI() {
return new Promise((resolve, reject) => {
$("#resume").change(function () {
var resumeNameValue = $("#resume")[0].files[0].name;
console.log($("#resume")[0].files[0]);
$("#resumeNameId").val(resumeNameValue);
var formData = new FormData();
formData.append('file', $("#resume")[0].files[0]);
console.log(formData);
$.ajax({
type: "post",
url: url,
data: formData,
processData: false,
contentType: false,
headers: {
'Access-Control-Allow-Headers': 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild'
},
success: function (data) {
resolve([data.data.name, data.data.url]);
if (data.code == 500) {
// alert(data.message);
} else {
// alert("简历上传失败!");
}
}
});
});
});
}