0
点赞
收藏
分享

微信扫一扫

jquery+js实现下载服务器目录中的文件

function templateDownLoad() {
$.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();
}

}

举报

相关推荐

0 条评论