使用jquery.fileDownload 插件来完成
js
var rq = data.rq ;
var djbh = data.djbh ;
//QuoteDownTemplate
var loading = layer.msg('正在处理中', {icon: 16, shade: 0.3, time:0});
var httpMethod = 'get';
var url = "/need/quote-down-template.html" ;
var params = {
rq: rq,
djbh: djbh
};
$.fileDownload(url, {
httpMethod: httpMethod,
// 因为这个插件貌似只支持URL参数,所以要用jquery param将js对象转成URL参数
data: $.param(params),
prepareCallback: function (url) {
console.log("导出中...")
},
//要想成功回调失败和成功方法,要在响应首部加 response.setHeader("Set-Cookie", "fileDownload=true; path=/");
successCallback: function (url) {
layer.close(loading);
layer.msg("导出成功");
},
failCallback: function (html, url) {
layer.close(loading);
layer.msg("导出失败");
}
})
后端
要想成功回调失败和成功方法,要在响应首部加 response.setHeader("Set-Cookie", "fileDownload=true; path=/");
Yii::$app->response->headers->set('Set-Cookie',"fileDownload=true; path=/");