I'm writing a plugin for wordpress, in page1.php
I have a form with a radio button and a submit button. The action of the form is myscript.php, How can I know when myscript.php has finished running?
page1.php:
echo '<form id="download_form" method="POST" action="myscript.php?download_the_excel=1">
<ol>
<li><input type="radio" name="input1" value="value1">radio_1</span></li>';
<li><input type="radio" name="input1" value="value2">radio_2</span></li>';
</ol>
<input id="export_button" type="submit" name="submit_button" value="Export">';
And then we have myscript.php
which is doing some calculation and finishes the script with some headers()
with an Excel attachment:
<?php
if(isset($_GET['download_the_excel']) && isset($_POST['input1']) && is_admin()){
$myData = some_huge_function();
$objPHPExcel = $myData;
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="filename.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
Now my problem is that when the user is on page1.php, and clicks the download button, I would like to put a Javascript loading(png image / loader / whatever..) while myscript.php
is running, and remove it after. How can I know when the script has finished?
Note: I can do something like that in page1.php
:
echo '<script>
$("#spinner_loader").hide();
$("#export_button").click(function(){
$("#spinner_loader").show();
});</script>';
When I do this, spinner_loader will never end (because page will not reload).