Reputation: 2579
Looking at the previous implementation of a site that I'm working on, I can see that we have an options form that is calling a ManageObject.php script. That script does some actions on a number of objects, and then returns to the page via the following code:
echo "<script type=\"text/javascript\"> window.history.back();</script>";
My javascript skills are very beginner-ish, but what I can tell is that it's just pressing the back button on the browser. This of course does not refresh the page, so all the data on that page is now old.
Is there a way to force a refresh on calling window.history.back()? Or is there a better way of calling the .php script without leaving the page and refreshing the page after the .php script has completed?
Upvotes: 1
Views: 1093
Reputation: 58921
There is a system called POST-redirect-GET, which solves this problem. It works like this:
In PHP you can redirect by calling header("Location: /path/to/page.php");
followed by exit();
. The advantage over the JavaScript way you posted in the question is that it does not require that the user has JavaScript enabled, and does not take the user to an intermediate page.
Upvotes: 1