1

What would be the best approach to give the user feedback, that a PHP script is running while they wait?

I've got a PHP script that runs via an AJAX call when a user clicks a button. The PHP script deals with large heavy images and takes some time before it is completed.

Because it is activated via an AJAX call, the user get's no visual feedback that the PHP script is running, because the user does not leave the page.

How do I go about giving some kind of visual feedback that something is happening via PHP in the background?

A simple .gif that is visible during the loading time of the script would suffice.

1

2 Answers 2

1

The easiest way to do it is to show the image as soon as the click takes place. You could do this by having an image already in place styled with display: none and then use jQuery's show() function to show it.

When you get your success message within your AJAX call, hide the image again.

1
  • Simple and effective, just what I was looking for. Thank you for your input
    – user25312
    Jun 11, 2013 at 14:32
1

If you have incremental activity that you want to show textually you can also direct the action at an iframe and have php echo and flush.

  echo "Beginning Step 1... <br/>";
  flush();
  // do step 1 
  echo "Step 1 Complete!<br/>";
  echo "Beginning Step 2...<br/>";
  flush(); 
  // etc..
1
  • Thank you, your answer helped me a lot. Jan 10, 2020 at 14:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.