jquery filedownload无法下载

时间:2017-06-17 07:42:27

标签: jquery

我正在尝试在我的代码中实现jquery filedownload但它没有按预期工作我使用本地系统作为我的文件系统下载文件可以有人帮助我这个我是jquery的新手或者更确切地说是提供了一个工作代码。

<%@ page language =" java"的contentType =" text / html的;字符集= ISO-8859-1"         的pageEncoding =" ISO-8859-1"%GT;                         

$(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>

1 个答案:

答案 0 :(得分:0)

你试过这样的事吗:

<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>