I am developing a rails app. (I don't think this is a rails-specific problem) There's a reservation process which is consisted of 3 steps. When a user is on step 2 page, if the user clicks 'Previous' button, the form data in step 1 should be the same as before.
我正在开发一个rails应用程序。 (我不认为这是特定于轨道的问题)有一个预订过程,包括3个步骤。当用户在第2步页面上时,如果用户单击“上一步”按钮,则步骤1中的表单数据应与之前相同。
I attached "history.go(-1);" to the 'Previous' button.
我附上“history.go(-1);”到“上一步”按钮。
It works on my firefox browser. But it doesn't work on some IE browsers. My IE works though.
它适用于我的Firefox浏览器。但它在某些IE浏览器上不起作用。我的IE工作。
How can I force it to preserve the form data when the page is back?
当页面返回时,如何强制它保留表单数据?
Thanks.
Sam
4 个解决方案
#1
Can't rely on the client (javascript) for this kind of operation.
不能依赖客户端(javascript)进行这种操作。
You save the data somewhere at step 1, so just restore it.
您可以在步骤1的某处保存数据,因此只需将其恢复即可。
#2
look into having a hidden iframe on the page to store the data. I am not sure of the specifics of implementing this, but this is the technique people use to store the state of the page when the hash changes in the URL. Check if some libraries like dojo and jquery help support this situation.
考虑在页面上有一个隐藏的iframe来存储数据。我不确定实现它的具体细节,但这是人们用来在URL中的哈希值发生变化时存储页面状态的技术。检查像dojo和jquery这样的库是否有助于支持这种情况。
#3
You could save page 2's data to the database, or a server-memory cache, or a cookie or three, and restore it when the page is loaded.
您可以将第2页的数据保存到数据库,服务器内存缓存或cookie或三个,并在加载页面时将其还原。
#4
ASP.NET does this automatically via ViewState (note: article is ancient, but still quite accurate). Perhaps you can adapt a similiar approach to Rails.
ASP.NET通过ViewState自动执行此操作(注意:文章很古老,但仍然非常准确)。也许你可以采用类似于Rails的方法。
#1
Can't rely on the client (javascript) for this kind of operation.
不能依赖客户端(javascript)进行这种操作。
You save the data somewhere at step 1, so just restore it.
您可以在步骤1的某处保存数据,因此只需将其恢复即可。
#2
look into having a hidden iframe on the page to store the data. I am not sure of the specifics of implementing this, but this is the technique people use to store the state of the page when the hash changes in the URL. Check if some libraries like dojo and jquery help support this situation.
考虑在页面上有一个隐藏的iframe来存储数据。我不确定实现它的具体细节,但这是人们用来在URL中的哈希值发生变化时存储页面状态的技术。检查像dojo和jquery这样的库是否有助于支持这种情况。
#3
You could save page 2's data to the database, or a server-memory cache, or a cookie or three, and restore it when the page is loaded.
您可以将第2页的数据保存到数据库,服务器内存缓存或cookie或三个,并在加载页面时将其还原。
#4
ASP.NET does this automatically via ViewState (note: article is ancient, but still quite accurate). Perhaps you can adapt a similiar approach to Rails.
ASP.NET通过ViewState自动执行此操作(注意:文章很古老,但仍然非常准确)。也许你可以采用类似于Rails的方法。