Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery FileDownload doesn't trigger successCallback Event

I'm trying to implement a function that on Click event, Download a file, and close the UI dialog When the file download is finished. The problem is the, after $preparingFileModal.dialog({ modal: true }) the code doesn't trigger anymore and successCallback cannot detect the end fo file download .

$(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>
like image 889
hello B Avatar asked Oct 26 '25 21:10

hello B


1 Answers

Have a look at Jquery File download ($.fileDownload)

You need to set header "Set-Cookie: fileDownload=true; path=/"

header("Set-Cookie: fileDownload=true; path=/"); is how I did it in PHP. I start zipping some files when the user clicks on the download button. After the zip file is created, I set the header as above and echo the zip file path to the browser and start the download via jqueryFileDownload.

//set filedownload cookie.
header('Set-Cookie: fileDownload=true; path=/');
echo json_encode(array("OK" => "Zip file created", 'file' => $zipFileName));
like image 189
harindra Avatar answered Oct 29 '25 11:10

harindra