How to display a loading image gif or message while PHP is executing a batch file?

前端 未结 3 2073
无人及你
无人及你 2021-02-01 11:29

I\'ve been searching on the net for the answer, but couldn\'t find.

How could I show some loading messsage or gif while the long executing script is running. I tested a

3条回答
  •  醉梦人生
    2021-02-01 12:01

    You can't do this using PHP only since is a server-side execution (the page / scripts are rendered in the server before the user can see anything on his browser)

    You should put your script in a separate file, and then do an AJAX call.

    To display the loading image follow this (jQuery framework needed)

    http://jquery-howto.blogspot.com/2009/04/display-loading-gif-image-while-loading.html

    // SHOW YOUR LOADING GIF HERE
    $('#result').load('yourscript.php', function() {
     //HIDE YOUR LODAING GIF HERE
    });
    

提交回复
热议问题