function templateDownLoad() {标签:jquery,function,text,js,pom,download,服务器,document,event From: https://blog.51cto.com/u_15890333/5883991
$.ajax({
url: resolve("aaa/bbb/ccc/targetFile.txt#"),
}).success(function (data,status) {
download('targetFile.txt',data);
})
}
function download(filename,text){
var pom = document.createElement("a");
pom.setAttribute(
"href",
"data:text/plain;charset=utf-8," + encodeURIComponent(text)
);
pom.setAttribute("download", filename);
if (document.createEvent) {
var event = document.createEvent("MouseEvents");
event.initEvent("click", true, true);
pom.dispatchEvent(event);
} else {
pom.click();
}
}