----------------图例(点击按钮,后台生成文件后,直接弹出该文件名称并选择下载位置)
------------------------------js
$.ajax({
type: 'post',
url: "${ctx}/sys/file/uploadWord",//后台地址,生成文件或其他逻辑
cache: false,
success: function(res){
//弹出下载链接
var url = "http://localhost:8011/canchu/"+res.filePath;
window.open(url,"_self");//重点
},
error: function(err){
console.log(err)
return;
}
});
--------------------说明
window.open(); 内只写文件地址,会跳转至新页面。加上_self会在当前页打开下载文件。