jQuery文件下载 - 就绪功能而不是点击功能

时间:2014-02-19 22:34:06

标签: javascript jquery ajax

我有以下jQuery代码,当单击超链接时,它会下载超链接href的文件。在准备文件时,它会显示一条请稍候的消息。

href代码是:

<a class="fileDownloadCustomRichExperience" href="pdf.php">Report Download</a>

我希望能够使用$(document).ready(function(){代替$(document).on(“click”)

来运行下面的代码

我尝试了ready(函数)但无法使href工作。

有什么建议吗?

由于

$(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!
    });
});

*解决如下:*

$(function () {
$( document ).ready(function() {

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

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

    $.fileDownload('pdf.php', {
        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!
});

});

0 个答案:

没有答案