[英]Refresh page to stop GIF animation loading(javascript) in PHP
我有一個GIF動畫,它將顯示何時提交表單,但是,何時成功執行php腳本; gif動畫不會停止...我嘗試執行包含'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" >   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';
如果我正確理解了您的問題,那么您想在單擊表單上的GENERATE REPORT
按鈕時顯示“正在加載”指示符,因為/phpexcelsample/download.php
將花費大量時間來運行。 您走在正確的軌道上,但是您需要擺脫以下兩行:
e.stopPropagation();
location.reload();
一旦/phpexcelsample/download.php
運行/phpexcelsample/download.php
,它將使用新內容更新瀏覽器窗口,從而消除“加載”指示符。 (這假設/phpexcelsample/download.php
將所需的結果頁面寫入瀏覽器。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.