2015-10-09 18:05


I need to create a loader div with an image while is loading

Here's my code:

    if (isset($_POST['restartserver']))

<div class="refresh">
<form method="post">
        <button class="button" name="restartserver">Restart Server</button>

So when i click on the button i need a loading image , when the is loaded the image-loader disapper and you can click again the button in the div.

Actually when i click on the button the script runs correctly but i see that the browser is loading the script, when finished it reload the same page.

I just want a loder image.gif when the script is loading

I know that this can be done with Ajax but i didn't find a working example

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • drsxzut183207938 drsxzut183207938 6年前

    Use jQuery for easy ajax. Following code assumes the restart script outputs "complete" when the reboot is done, and anything else for an error.

    $('#loaderdiv').html('<img src="loader.gif" />');
    $.get('', function(data){
        if (data == "complete"){
           $('#loaderdiv').html('Reboot Complete');
        } else {
           $('#loaderdiv').html('An Error Has Occured');


    <div id="container">
        <button id="runscript">Run Script</button>


          $('#container').html('<img src="loader.gif" />');
          $.get('', function(data){
                // Code here executes once ajax is complete
                $('#container').html('**strong text**');
    点赞 评论 复制链接分享