0

I want to show an loading GIF while my PHP-script is working, small ex:

HTML CODE WITH LOADING.GIF

PHP CODE

sleep(5)
echo("<script>location.href = 'http://www.google.com';</script>");

If i run this example the page will load in 5 seconds, then show me the loading.gif in 0.3seconds and then send me to google. Is there any way to load all html to the browser then runt the PHP-script?

1 Answer 1

5

Due to your HTTP server's output bufferring you can't predict when different parts of your script's output will reach the browser. Instead, you should load a simple "Loading..." page and from that page use Javascript to fire an AJAX request to trigger the "working" of your current PHP script, then grab the output and replace the content of the loading page with it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.