gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 04:23:38 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com