javascript - 刷新页面以停止 PHP 中的 GIF 动画加载(javascript)

标签 javascript php html

我有一个 GIF 动画,当表单提交时显示,但是当 php 脚本成功执行时显示; gif 动画不会停止...我尝试执行 include 'index.php' 但是,它仍然无法正常工作,您能帮我了解如何执行此操作吗?

javascript中的GIF动画函数称为ShowLoading()

这是我的html代码:

    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>

 <link rel="stylesheet" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css">
 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 <linkrel="stylesheet"href="https://cdn.datatables.net/fixedheader/3.1.2/css/fixedHeader.bootstrap.min.css">
 <link rel="stylesheet" href="https://cdn.datatables.net/responsive/2.1.1/css/responsive.bootstrap.min.css">
     <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

 </head>


    <script type="text/javascript">
function ShowLoading(e) {
    var div = document.createElement('div');
    var img = document.createElement('img');
    img.src = 'buffer.gif';
    div.innerHTML = "<p style='color:red;'>Generating report... This might take a while..</p><br />";
    div.style.cssText = 'position: absolute; bottom: 250px; left: 35%; z-index: 5000; width: 422px; text-align: center';
    div.appendChild(img);
    document.body.appendChild(div);
    return true;
    // These 2 lines cancel form submission, so only use if needed.
   // window.event.cancelBubble = true;
    e.stopPropagation();
   location.reload();
}


  </script>

     <body>
      <br />

      <form method ="POST" action="/phpexcelsample/download.php" onsubmit="return checkURL();"> 




<center>  
    <div class="parent_div">  

    <p>Date From: <input type="text" class ="textbox" id="datepicker" value="<?php echo date("Ymd"); ?>" name="datepicker" readonly="True" > &emsp;  Date To:<input type="text" class ="textbox" id="datepicker1" value="<?php echo date("Ymd"); ?>" name="datepicker1" readonly="True" > </p>

            <br />
            <br />

            <input type="submit" class = "generate" name="submit" value="GENERATE REPORT" onclick="ShowLoading()" <?php if(isset($_POST['submit'])) echo 'disabled="disabled"'; ?> > <br />

    </div>
          </center> <br />

</body>

</html>

这是我的php代码:

这是一个使用 PHPexcel 的长 PHP 代码,我只是要显示最后几行或 PHPExcel 的输出,包括 include 'index.php';

 header('Content-Type: application/vnd.ms-excel'); 
header('Content-Disposition: attachment;filename="Result.xls"'); 
header('Cache-Control: max-age=0'); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 
$objWriter->save('php://output');

include 'index.php';

最佳答案

如果我正确理解您的问题,您希望在单击表单上的生成报告按钮时显示“正在加载”指示器,因为/phpexcelsample/download.php将需要大量的时间来运行。您的方向是正确的,但您需要删除这两行:

e.stopPropagation();
location.reload();

一旦/phpexcelsample/download.php运行完毕,它将用新内容更新浏览器窗口,删除“正在加载”指示器。 (假设 /phpexcelsample/download.php 将所需的结果页面写入浏览器。)

关于javascript - 刷新页面以停止 PHP 中的 GIF 动画加载(javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45249880/

相关文章:

php - mySQL 查询在 WordPress 网站上执行两次

javascript - 从 C# 到 javascript 的等效正则表达式模式

javascript - 如何将azure移动服务连接到ionic应用程序

javascript - JQuery - 获取宽度 : auto from inline style

html - 延迟 HTML5 :invalid pseudo-class until the first event

php - 如何使用记录插入向导上传文件? php 的 Dreamweaver

javascript - 如何存储包含参数的 JS 函数引用

javascript - 单击按钮时提供新项目

php - 数据库中的值未显示

javascript - 验证后如何保留表单值