//页面部分
<div class="top-left">
<form id="domainExtendMsgSubmitForm" action="<%=path%>/domain/domainExtendMsgImport.htm" enctype="multipart/form-data" method="post">
<input type="file" name="file" style="color: white;" />
<input type="hidden" name="pageCount" value="${page.rowCount }" />
<input type="button" value="导入excel" onclick="domainExtendMsgSubmit()"/><span style="font-size:10px; color: white; ">(仅支持xls格式)</span>
</form>
</div>
<form id="domainExtendMsgSubmitForm" action="<%=path%>/domain/domainExtendMsgImport.htm" enctype="multipart/form-data" method="post">
<input type="file" name="file" style="color: white;" />
<input type="hidden" name="pageCount" value="${page.rowCount }" />
<input type="button" value="导入excel" onclick="domainExtendMsgSubmit()"/><span style="font-size:10px; color: white; ">(仅支持xls格式)</span>
</form>
</div>
//js部分:
function domainExtendMsgSubmit() {
// $("#domainExtendMsgSubmitForm").submit();
//domainExtendMsgSubmitForm为form表单id
var formData = new FormData($("#domainExtendMsgSubmitForm")[0]);
//formData.append('sgid',_sgId); 添加表单之外的参数
$.ajax({
url: '<%=path%>/domain/domainExtendMsgImport.htm',
type: 'POST',
data: formData,
cache: false,
dataType: "json", //预期服务器返回的数据类型
//注意这里一定要设置contentType:false,不然会默认为传的是字符串,这样文件就传不过去了
contentType: false,
processData: false,
success: function (data) {
if (data.code == 0) {
window.location.reload();
} else {
alert(data.msg);
window.location.reload();
}
},
error: function (data) {
alert(data.msg);
}
});
}