下面是我编写的代码:
JS:
$(function() {
$('#theForm').on('submit', sendFile);
});
function sendFile(e) {
e.preventDefault();
// get the reference to the actual file in the input
var theFormFile = $('#theFile').get()[0].files[0];
$.ajax({
type: 'PUT',
url: 'MY PRESIGNED URL HERE',
dataType : 'jsonp',
crossDomain:true,
contentType: false,
headers: {'Content-Type': 'multipart/form-data'},
processData: false,
data: theFormFile,
error: function () {
alert('File NOT uploaded');
},
success: function () {
alert('File uploaded');
}
})
};
HTML代码:
<form id="theForm" method="POST" enctype="multipart/form-data" >
<input id="theFile" name="file" type="file"/>
<button id="theButton" type="submit" class="upload-current-resume-linkedin btn-success">Upload</button>
</form>
输出: AJAX每次都会出错。 “文件未上传”
请指导我以上代码中需要进行哪些纠正。