【发布时间】:2014-08-03 09:45:32
【问题描述】:
我有一个 div,其中包含在提交表单时触发的“处理”动画。
<form action='index.php?page=2' method='post' onsubmit="javascript:processingBox();">
适用于大多数页面。 我遇到的问题是,我的一些表单使用以下代码触发了下载:
//BEGIN DOWNLOAD HEADER SECTION//
header("Pragma: public", true);
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition: attachment; filename='.$filename);
header("Content-Transfer-Encoding: binary");
header('Connection: Keep-Alive');
//WRITE OUT HEADER//
echo $output;
//WRITE OUT RECORDS//
while ($row = mysqli_fetch_array($sql)) {
$output = "";
for ($i = 0; $i < $columns_total; $i++) {
$output .= $_POST['enclosed'] . $row["$i"] . $_POST['enclosed'] . $_POST['delimiter'];
}
echo "\r\n";
echo substr($output,0,strlen($output)-1);
}
exit;
这里明显的问题是,这个脚本不会刷新页面(因为它的设计目的是不刷新),但它不会清除提交时可见的处理启动画面。
此方案的任何最佳实践?
编辑:
<script type="text/javascript">
function processingBox() {
div = document.getElementById('processingBox');
div.style.visibility = "visible";
}
</script>
<div class='processingBox' id='processingBox'>
<h1 style='margin-top:0px;margin-bottom:30px;'>Processing</h1>
<div class="circle"></div>
<div class="circle1"></div>
</div>
【问题讨论】:
-
下载是通过 AJAX 完成的?如果是这种情况,那么您也需要在 JavaScript 中隐藏您的“动画”。通常,您应该能够在 Ajax 调用中指定返回函数。上传文件时,应调用此函数。从中,你会隐藏你的动画。
-
显示
processingBox()函数。 -
还有上传表单的 HTML 和 JavaScript 代码...
-
这不是在 AJAX 中完成的。它已更新为显示 processingBox() 函数和框本身的 HTML。此外,没有上传,它严格从 mysql 表中导出数据。
标签: php