I am trying to display a loading message with an loading bar animation so people know the script is working away.
However even though the HTML is at the top of my PHP script , it only gets displayed once the script is fully loaded.
The script takes about 40 seconds to complete because it Generates a PDF, Inserts Data into a DB then sends a MIME email to an external MX (takes the longest part).
Here is the HTML that displays the loading message:
<div class="grid_16">
<fieldset>
<h2>
Processing <img src="img/loading.gif" alt="loading animation">
</h2>
</fieldset>
</div>
<?php
//rest of php page
Any idea how I display this out to the user so they don’t get impatient and start hitting F5 etc.
Thanks
Merry Christmas!
PHP loads on the server and is then passed to the browser. This means that, until the page has completely finished loading on the server it will not be passed to the browser for display.
What you will need to do is use javascript and ajax. Firstly, remove the slow PHP from the HTML and show the page. Then once that has shown load the PHP script via ajax and once it has completed write it to the document.