Using Javascript function after submitting a POST form

In my web application, I provide a link that takes it to another page, shows some data, pops up the page and returns with the javascript back () function.

It worked fine, but it fails in some cases. For example, this link appears after submitting the form. When back () is called here, a Webpage message is displayed because it was a POST operation.

How can I go back to the previous page using javascript in this situation?

Please provide your details ...

+2


source to share


2 answers


You can't do anything after the page expires with JavaScript - the way the browser prefers to protect the user from accidentally resubmitting the form.

You can use the POST / Redirect / GET method , depending on how your application is doing, so that users always land on a GET after submitting their form, so you always have the correct state to return to.



In all honesty, 99% of the time using functionality back()

in JavaScript is a sign of something wrong in the basic approach. It's too problematic to be workable, as you see here. You can get more information if you start a new question to describe what you are trying to accomplish. There are so many really smart people out there who can all put their heads together and help you come up with something.

+1


source


Can you explain why you need to navigate to the previous page using a client-side script? I am assuming this because the user may come to this page from different pages and you want to direct them back to the page they came from. You can always store the URL of the user's previous page in a session or cache object and redirect them back to that URL in server-side code. Or, if you know where they will always be from, cast them back to a static url. I can offer more help if you can provide more details.



0


source







All Articles