下载文件时,加载图标会一直显示 [英] Loading icon keeps on displaying while downloading a file

查看:80
本文介绍了下载文件时,加载图标会一直显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下载pdf文件时,加载图标会一直显示在页面中。下载文件时似乎触发了beforeunload功能。我的代码中会出现什么错误?



t1.php

When downloading a pdf file, loading icon keeps on displaying in the page. It seems like beforeunload function is getting triggered when downloading a file. What would be the mistake in my code?

t1.php

<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
</head>
<body>
<script>
        $(window).on('beforeunload', function(event) {
            $('#loading').show();
        });
        $(window).on('load', function(event) {
            $('#loading').hide();
        });
 </script>  
 <div id="loading">Loading...</div>
 <a href="t1.php?pdf=<?php echo 'Intro.pdf';?>"><button>download</button></a>
    <?php
        if(isset($_GET['pdf'])){
            $bbpdf = $_GET['pdf'];
            header("Pragma: public"); // required
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: private", false); // required for certain browsers
            header("Content-Type: application/pdf");
            header("Content-Disposition: attachment; filename=\"" . basename($bbpdf));
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: " . filesize($bbpdf));
            ob_clean();
            flush();
            readfile($bbpdf);
        }        
    ?>
</body>
</html>

推荐答案

window )。on(' beforeunload' function (event){
(window).on('beforeunload', function(event) {


' #loading')。show();
});
('#loading').show(); });


window )。on(' load' function (event){
(window).on('load', function(event) {


这篇关于下载文件时,加载图标会一直显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆