سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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..
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top