2017-06-17 36 views
0

我想實現我的代碼的jQuery filedownload但我使用本地系統作爲我的文件系統來下載文件有人可以幫助我在這方面,我是新來的jQuery或預期它不工作而是提供一個工作代碼。jQuery的filedownload無法下載

<%@頁語言= 「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> 
+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> 
+0

2017年6月17日上午11時52分44秒開始org.apache.tomcat.util.digester.SetPropertiesRule 警告:[SetPropertiesRule] {服務器/服務/發動機/主機/上下文}設定屬性 '源' 到「org.eclipse .jst.jee.server:Filedownload'找不到匹配的屬性。 2017年6月17日上午11:52:44 – Anshuman

+0

仍然沒有工作@Riaz拉斯卡我發佈了我得到的錯誤。 – Anshuman

+0

請致電............................................... .... – Anshuman