开发者

Show loading image while PHP work

I want to show an loading GIF while my PHP-script开发者_JAVA技巧 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜