$("#file").off("change").on("change",function(){
var inputFile = $('#file').get(0).files[0];
if(inputFile && (inputFile.name.endsWith("doc") || inputFile.name.endsWith("docx"))){
$("#span").html(inputFile.name);
}else{
window.wxc.xcConfirm("请上传word文件!", "error");
return ;
}
});

<form id="addForm" class="form-horizontal" enctype="multipart/form-data">
<input type="file" accept="application/pdf" id="file" name="file" style="display:none">
</form>
$("#BA_Btn").click(function(){
var s=$("#span").html();
var form = new FormData(document.getElementById("addForm"));
$.ajax({
type: "POST",
url: "<%=basePath%>backend/sjxq/add",
data: form,
async: false,
processData: false,
contentType: false,
success: function (result) {
window.history.back();
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
window.wxc.xcConfirm("保存失败", "error");
return ;
},
});
});

注意     :上传文件的文件流是无法被序列化并传递的。

对于单个文件,不放在form表单里面的,比如

<input type="file" multiple="multiple" name="file" id="file">

多文件需要遍历append进去,

function aaa(){
var formData = new FormData();
var file = $("#file").get(0).files;
for(var i=0;i<file.length;i++){
formData.append('file',file[i]);
}
$.ajax({
url : "http://localhost:8080/datahalls/page/test",
type : 'POST',
data : formData,
processData : false,
contentType : false,
cache: false,
success:function(data){
alert(111)
}
})

}