2017-06-17 147 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