简体   繁体   中英

How to “GO BACK” to the previous page after submit is clicked on a form?

I'm working on a project on grails.

I have a filter page (Filters.html) where i can perform a search with various parameters. After the search is performed the results will get displayed. (results.html) In the results page it has a link to update a record. (update.html) Once clicked on the update link it will take to the update html page, in that page there is a back button also there is a form so that the details can be updated and saved.

With window.history.go(-1); and window.history.back() it goes to the back page without any issue. But the issue arises when the form details are updated. When the form is submitted it comes to the same update page and shows that the records were updated. Afterward when clicked on the BACK button it goes to the same page. But doesnt go back to the results page. If i click on the BACK button twice it will go back to the results page.

I cant save the search parameters in the update page as there are several ways to go to the update.html. Any suggestion ?

Rather than re-render the update page after a successful update you could redirect back to the results view.

update() {
    // do the update
    redirect( action: 'results' )
}

Or rather than have a back button, have a button that takes you directly to the results view:

<g:link action="results"><button type="button" value="Results">Results</button></g:link>

How about creating a variable called numUpdates (anything). Increment the variable when the form is updated, and have the "GO BACK" button call window.history.go(-1*numUpdates).

Change the URL of the page the form submits to, adding a parameter to the end

eg update.html?submitted=true

Then create an if statement, that if the URL contains submitted=true (or whatever text you pick), change the back button URL to results.html.

Hope this makes sense.

If you're still stuck, I can type up the code for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM