导出(请求后端接口)
<a class="btn btn-warning ListExp" id="export" style="display: none">
<i class="glyphicon glyphicon-download-alt"></i> 导出
</a>
$('#export').click(function () {
$('#export1').attr('href',url+'/customer/export')
})
有的接口:
<img title="下载" style="margin-left: 10px;" src="../../img/export.png" class="clickResult" alt="" id="export">
location.href=url+"/power_static/downloadExcel?short_addr='"+AddStr
导入
<div class="wrapper wrapper-content animated fadeInRight ibox-content col-sm-12" id="ListImport" style="display: none">
<div class="row" style="margin-left: 10%">
请选择导入的文件
<form action="#" id="backImage">
<input type="file" id="file_input" name="file" multiple/>
</form>
</div>
复制代码
// 点击的弹框
$('#Import').click(function () {
layer.open({
title: '导入表格',
type: 1,
area: ['400px', '200px'],
content: $("#ListImport"),
btn: ["确定", "关闭"],
btn1: function () {
ImportFun()
}
});
})
//导入函数
function ImportFun() {
var formData=new FormData($('#backImage')[0])
var files = $('#file_input')[0].files[0];
formData.append('file',files)
$.ajax({
url: url + "/customer/import",
type: "post",
data: formData,
processData: false, // 告诉jQuery不要去处理发送的数据
contentType: false, // 告诉jQuery不要去设置Content-Type请求头
success:function (res) {
console.log(res)
layer.msg('导入成功')
}
});
}
复制代码