我正在使用jquery ajax将excel文件上传到数据库中。问题是,在成功上传文件后,我想清除文件上传,这样如果我再次按下按钮,它就不会上传同一个文件(它当前是) 我尝试了以下但没有运气。我试着把.value =“”(没有运气)。
$(document).ready(function () {
$('#btnBankFileUpload').click(function () {
if (window.FormData !== undefined) {
var fileUpload = $("#fileUploadMenu").get(0);
var files = fileUpload.files;
// Create FormData object
var fileData = new FormData();
// Looping over all files and add it to FormData object
for (var i = 0; i < files.length; i++) {
fileData.append(files[i].name, files[i]);
}
$.ajax({
url: '/Home/Index',
type: "POST",
contentType: false, // Not to set any content header
processData: false, // Not to process data
data: fileData,
success: function (result) {
$('#uploadMessage').text(result);
$('#lblFilePath').text(" ");
var fileuploadmenu = $("#fileUploadMenu");
fileuploadmenu.innerHTML = fileuploadmenu.innerHTML;
},
error: function(err) {
alert(err.statusText);
}
});
}
});
});
答案 0 :(得分:0)
试试这个
$("#fileUploadMenu").val(null); //Clear Uploaded File