我有一个启动PHP脚本的HTML链接:
<a id="exportExcel" href = 'PHPScript.php'>Dowload File</a>
此链接不会打开任何其他窗口。它只是创建并向用户发送Excel文件(使用phpExcel)。
//Include the PHPExcel library
include ('/lib/PHPExcel/PHPExcel.php');
include ('/lib/PHPExcel/PHPExcel/IOFactory.php');
//Create a new Excel File
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();
$indiceColumn = "A";
$indiceLine = 1;
//Put data in the ExcelFile
$listColumnName = mysql_query("select * FROM my_table WHERE config = ".$id_config." ORDER BY id");
while($columnName = mysql_fetch_object($listColumnName))
{
$sheet->SetCellValue($indiceColumn.$indiceLine, $columnName->csv_nom_col);
$indiceColumn++;
}
//Send the file to the user
$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
header('Content-Type: application/application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="template.xls"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
但是创建文件需要一些时间,所以当用户点击我的链接时会显示一个loadBar。
$("#exportExcel").click(function()
{
$("#loadBar").show();
});
它有效,但我不知道何时必须隐藏它。我想要的是在用户收到文件或PHPScript完成时隐藏loadBar。