简体   繁体   English

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

[英]Refresh page to stop GIF animation loading(javascript) in PHP

I have a GIF animation that will show when the form is submitted, however, when the php script is executed successfully; 我有一个GIF动画,它将显示何时提交表单,但是,何时成功执行php脚本; the gif animation won't stop... I tried to do the include 'index.php' however, its still not working, can you help me on how to do this? gif动画不会停止...我尝试执行包含'index.php'的操作,但是仍然无法正常工作,您能帮我怎么做吗?

The GIF animation function in javascript is called ShowLoading() javascript中的GIF动画函数称为ShowLoading()

Here's my html code: 这是我的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>

Here's my php code: 这是我的PHP代码:

This is a long php code that uses PHPexcel, I'm just gonna show the last few lines or the output of the PHPExcel including the include 'index.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';

If I understand your question correctly, you want to display your "loading" indicator when the GENERATE REPORT button on your form is clicked because /phpexcelsample/download.php is going to take a significant amount of time to run. 如果我正确理解了您的问题,那么您想在单击表单上的GENERATE REPORT按钮时显示“正在加载”指示符,因为/phpexcelsample/download.php将花费大量时间来运行。 You're on the right track, but you need to get rid of these two lines: 您走在正确的轨道上,但是您需要摆脱以下两行:

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

Once the /phpexcelsample/download.php gets done running, it will update the browser window with the new contents, erasing the "loading" indicator. 一旦/phpexcelsample/download.php运行/phpexcelsample/download.php ,它将使用新内容更新浏览器窗口,从而消除“加载”指示符。 (This is assuming /phpexcelsample/download.php writes the desired result page to the browser.) (这假设/phpexcelsample/download.php将所需的结果页面写入浏览器。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM