当发出变量文件的警报时,它显示它包含文件,但是当它返回时它显示没有发送文件,下面是我使用的代码
$(document).ready(function (e) {
var sid = getUrlVars()["id"];
var fileInput = document.getElementById('file');
//get file in variable
var file = fileInput.files[0];
$("#uploadimage").on('submit',(function(e) {
var inputData = new FormData($(this)[0]);
alert(inputData);
e.preventDefault();
$("#message").empty();
$('#loading').show();
$.ajax({
headers: {
'Authorization': 'Bearer '+ localStorage.token,
'Content-Type': 'application/x-www-form-urlencoded'
},
url: "api/v1/uploadReport/" + sid,
type: "POST", // Type of request to be send, called as method
data: fileInput,
async: false,
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data) // A function to be called if request succeeds
{
$('#loading').hide();
$("#message").html(data);
}
});
}));