我试图在我的代码中实现jquery filedownload,但它没有像预期的那样工作,我使用本地系统作为我的文件系统来下载文件,有人能在这方面帮助我吗?我是jquery的新手,或者更确切地说,提供了一个工作代码。
<%@ page language="java“contentType="text/html;字符集=ISO-8859-1”pageEncoding="ISO-8859-1"%>
$(document).on("click", "a.fileDownloadSimpleRichExperience", function () {
$.fileDownload($(this).prop('href'), {
preparingMessageHtml: "We are preparing your report, please wait...",
failMessageHtml: "There was a problem generating your report, please try again."
});
return false; //this is critical to stop the click event which will trigger a normal file download!
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="E://Download/Anshuman.txt" class="fileDownloadSimpleRichExperience">Download</a>
</body>
</html>发布于 2017-06-17 15:52:21
你试过这样做吗:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="E://Download/Anshuman.txt" class="fileDownloadSimpleRichExperience">Download</a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).on("click", "a.fileDownloadSimpleRichExperience", function (e) {
e.preventDefault();
var hiddenElement = document.createElement('a');
hiddenElement.href = $(this).attr('href');
hiddenElement.download = 'aaa.csv';
hiddenElement.click();
});
</script>
</body>
</html>https://stackoverflow.com/questions/44602060
复制相似问题