jQuery文件下载插件 - 我无法弄明白

时间:2017-03-13 17:20:52

标签: jquery cookies download setcookie

我有一张PDF,当我点击它的链接时,我试图强行下载。我偶然发现了jQuery File Download Plugin。这正是我正在寻找的东西,但我不能让它为我的文件工作。

我认为设置Cookie存在问题,但我无法在线找到有关如何实施Cookie的参考资料,而且我无法理解说明在网站上。我试图查看Demo链接到的URL的代码,但它只是PDF代码。

来自Demo of jquery.fileDownload.js的链接正常工作,但我的链接却没有。这是我现在拥有的。我已经尝试了8个小时才能让这个东西工作,我只是没有理解我错过的东西......好吧,就像我说的,我确定它&#39 ;是cookie,但我找不到如何实现它(或iFrame)的例子...演示对我来说没有意义。

非常感谢任何帮助。提前谢谢!

以下是我目前的情况:

<!DOCTYPE HTML>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">

        <title>PDF Download Test</title>

        <link type="text/css" rel="stylesheet" href="site.css" />     
        <link type="text/css" rel="stylesheet" href="jquery-ui-2.css" />
        <script type="text/javascript" src="jquery.min.js"></script>
        <script type="text/javascript" src="jquery-ui.min.js"></script>
        <link type="text/css" href="jquery-ui.css" rel="stylesheet">
        <script type="text/javascript" src="jquery.filedownload.js"></script>
        <script type="text/javascript" src="shcore.js"></script>
        <script type="text/javascript" src="jquery.gritter.min.js"></script>        

</head>
<body>

<script type="text/javascript">
    $(function () {

        //Custom rich user experience - jquery.fileDownload.js & jQuery UI Dialog
        //uses the optional "options" argument
        //
        //      the below uses jQuery "on" http://api.jquery.com/on/ (jQuery 1.7 + required, otherwise use "delegate" or "live") so that any 
        //      <a class="fileDownload..."/> that is ever loaded into an Ajax site will automatically use jquery.fileDownload.js
        //      if you are using "on":
        //          you should generally be able to reduce the scope of the selector below "document" but it is used in this example so it
        //          works for possible dynamic manipulation in the entire DOM
        //
        $(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!
            });
        });

    })
</script>



    <!-- My PDF -->
    <p><a class="fileDownloadCustomRichExperience" href="/Jobsite_Account_Setup_Form.pdf">Download My PDF &#8250;&#8250;</a></p>


    <!-- jQuery File Download DEMO LINKS -->
    <p><a class="fileDownloadCustomRichExperience" href="http://jqueryfiledownload.apphb.com/FileDownload/DownloadReport/0">Report0.pdf</a>This file download will succeed</p>

    <p><a class="fileDownloadCustomRichExperience" href="http://jqueryfiledownload.apphb.com/FileDownload/DownloadReport/1">Report1.pdf</a>This file download will fail</p>



    <!-- Modal Box & Progress Bar -->
    <div id="preparing-file-modal" title="Preparing report..." style="display: none;">We are preparing your download, 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 download, please try again.
    </div>



</body>
</html>

0 个答案:

没有答案