简体   繁体   English

单击表单上的提交后,如何“返回”上一页?

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

I'm working on a project on grails. 我正在从事Grails项目。

I have a filter page (Filters.html) where i can perform a search with various parameters. 我有一个过滤器页面(Filters.html),可以在其中执行各种参数的搜索。 After the search is performed the results will get displayed. 执行搜索后,将显示结果。 (results.html) In the results page it has a link to update a record. (results.html)在结果页面中,它具有更新记录的链接。 (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. (update.html)单击更新链接后,将转到更新html页面,在该页面中有一个后退按钮,还有一个表格,以便可以更新和保存详细信息。

With window.history.go(-1); 使用window.history.go(-1); and window.history.back() it goes to the back page without any issue. 和window.history.back()可以无任何问题地转到后页。 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. 我无法将搜索参数保存在更新页面中,因为有几种方法可以访问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). 如何创建一个名为numUpdates(任何)的变量。 Increment the variable when the form is updated, and have the "GO BACK" button call window.history.go(-1*numUpdates). 表单更新时增加变量,并具有“ GO BACK”按钮,调用window.history.go(-1 * numUpdates)。

Change the URL of the page the form submits to, adding a parameter to the end 更改表单提交到的页面的URL,在末尾添加一个参数

eg update.html?submitted=true 例如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. 然后创建一个if语句,如果URL包含Submitted = true(或您选择的任何文本),则将后退按钮URL更改为results.html。

Hope this makes sense. 希望这是有道理的。

If you're still stuck, I can type up the code for you 如果您仍然遇到问题,我可以为您输入代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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