Jquery FileDownload不会触发successCallback事件

hel*_*o B 2 javascript jquery jquery-ui

我正在尝试实现一个函数,在Click事件,下载文件,并关闭UI对话框文件下载完成后.问题是,$preparingFileModal.dialog({ modal: true })代码不再触发后 successCallback无法检测到文件下载结束.

$(function () {
    $(document).on("click", "a.fileDownloadCustomRichExperience", function () {

        var $preparingFileModal = $("#preparing-file-modal");

        $preparingFileModal.dialog({ modal: true });

        $.fileDownload($(this).prop('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>
Run Code Online (Sandbox Code Playgroud)

小智 8

看看Jquery文件下载($ .fileDownload)

你需要设置标题 "Set-Cookie: fileDownload=true; path=/"

header("Set-Cookie: fileDownload=true; path=/");我是怎么用PHP做的.当用户点击下载按钮时,我开始压缩一些文件.创建zip文件后,我设置上面的标题并回显浏览器的zip文件路径并通过jqueryFileDownload开始下载.

//set filedownload cookie.
header('Set-Cookie: fileDownload=true; path=/');
echo json_encode(array("OK" => "Zip file created", 'file' => $zipFileName));
Run Code Online (Sandbox Code Playgroud)