ajax文件上传,谷歌正常IE报错问题错误内容
出现这个问题查三个地方:
1、form中是否写了enctype="multipart/form-data"
<form id="myform" method="post" enctype="multipart/form-data">
2、是否设置临时目录,临时目录是否有写入权限
springboot项目在application.yml中增加配置项
spring:
application:
name: xxxxx
http:
multipart:
enabled: true # 启用http上传处理
max-file-size: 100MB # 设置单个文件的最大长度
max-request-size: 100MB # 设置最大的请求文件的大小
file-size-threshold: 1MB # 当上传文件达到1MB的时候进行磁盘写入
location: / # 上传的临时目录
3、input不要漏了name属性
input不要漏name属性,如果漏了,IE下会上传失败,谷歌没问题
漏写name标签导致IE下上传文件不可用
正确写法:
---------------------------------------------------------------------
示例页面
<form id="myform" method="post" enctype="multipart/form-data">
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" id="exceladd" name="excelFile" style="display: none; " @change="copyFile()" >
<input type="text" name="keepoutInput" style="width:160px; height:25px" id="keepoutInput" ></hy-input>
<hy-button text ="选择excel" @click="click1()" ></hy-button>
<hy-button text ="上传" @click="winconfirms()" ></hy-button>
</form>
js
$.ajax({
url: $$pageContextPath + "/xxx/xxxxx/iptExcelController",//这里写你的url
type: 'POST',
cache: false,
data: new FormData($('#myform')[0]),
processData: false,
contentType: false
}).done(function(res) {
ajaxbg.hide();
var msg =res.parameters.message;
var message = msg ;
if(msg==4){
$("#keepoutInput").val("");
$.alert("选择上传文件的模板错误 ");
}else if(msg==20){
$("#keepoutInput").val("选择上传文件不符合上传条件数据");
$.alert("选择上传文件数据不符合上传条件");
}
}).fail(function(res) {});
后台