我正在使用jquery文件下载..
代码如下:
function downloadFile(){
var downloadOptions = {
preparingMessageHtml: "We are preparing your report, please wait...",
failMessageHtml: "No reports generated. No Survey data is available."
};
$.fileDownload("displaySurveyReport.action",downloadOptions);
return false;
}
这就是我点击按钮时所做的事情
当我点击按钮时,prepareMessageHtml:“我们正在准备你的报告,请稍候......”,显示在一个对话框中...... 问题是,在fle完成准备后,此对话框不会关闭,我必须手动关闭它... 如何在文件完成准备并准备下载时将其关闭..
由于
答案 0 :(得分:19)
为了使JQuery知道文件下载刚刚出现,您的响应头必须包含Set-Cookie: fileDownload=true; path=/
。
在Java中:
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
答案 1 :(得分:2)
这是jquery文件下载的源代码..
$(function () {
$(document).on("click", "a.fileDownloadCustomRichExperience", function () {
var $preparingFileModal = $("#preparing-file-modal");
$preparingFileModal.dialog({ modal: true });
$.fileDownload($(this).attr('href'), {
successCallback: function (url) {
$preparingFileModal.dialog('close');
},
failCallback: function (responseHtml, url) {
$preparingFileModal.dialog('close');
$("#error-modal").dialog({ modal: true });
}
});
return false; //this is critical to stop the click event which will trigger a normal file download!
});
});
<div id="preparing-file-modal" title="Preparing report..." style="display: none;">
We are preparing your report, please wait...
<div class="ui-progressbar-value ui-corner-left ui-corner-right" style="width: 100%; height:22px; margin-top: 20px;"></div>
</div>
<div id="error-modal" title="Error" style="display: none;">
There was a problem generating your report, please try again.
</div>
答案 2 :(得分:1)
成功;
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
出错
response.setHeader("Set-Cookie", "fileDownload=false; path=/");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
使用&#34;缓存控制&#34;只有在他人提出要求时才会存在。
答案 3 :(得分:0)
某些浏览器还需要您重置响应,否则您的下载将无效!
response.reset();
答案 4 :(得分:0)
请尝试这样
0
的反对意见
我希望它对你有用..