MVC Ajax表单和浏览器后退按钮 [英] MVC Ajax form and browser back button

查看:36
本文介绍了MVC Ajax表单和浏览器后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在MVC网站上工作,该网站的搜索页面位于登录页面的后面.用户登录后,他们将被重定向到搜索页面.

I am currently working on an MVC site which has a search page that sits behind a login page. When the user logs in, they are redirected to the search page.

搜索表单使用ajax表单,该表单会将搜索结果返回到同一视图.

The search form uses an ajax form that returns search results to the same view.

获得搜索结果后,将不再显示搜索表单.一切正常.

When we have search results, the search form is no longer shown. This all works fine.

但是,一旦您退出表单并获得搜索结果-用户可能会尝试按浏览器的后退"按钮尝试返回搜索表单.当然,这会将它们带到上一页(登录页面).

However, once you have fired off the form and have search results - the user will probably try and hit the browser back button to try and get back to the search form. Of course, this instead takes them to the previous page (the login page).

所以,我的问题是-我仍然想使用ajax将表单和结果保留在同一页面上.无论如何,与用户单击时将其带到搜索表单一起,我是否可以实现这一目标?

So, my question is this - I would still like to keep the form and results on the same page using ajax. Is there anyway that I can achieve this, in conjunction with when the user clicks back, it takes them to the search form?

我很欣赏我可能在这里要求太多,但是我想我还是会把它放在那里!

I appreciate I am probably asking for too much here, but I thought I'd put it out there anyway!

ps-我已经有了一个返回搜索"链接,该链接可以重新加载表格.我相信普通用户会尝试单击浏览器的后退按钮.我也希望登录页面上没有某种将其重定向回搜索页面的功能.

ps - I already have a 'back to search' link which re-loads the form. I believe the average user will try and click the browser back button. I would also rather not have some sort of function on the login page that redirects them back to the search page.

推荐答案

您需要使用历史API .现代浏览器支持该功能,并且针对IE9及更低版本有一个 polyfill .

You need to use the History API. It's supported in modern browsers, and there's a polyfill for IE9 and below.

更新

对于它的价值,我同意@TravisJ.这是一个糟糕的设计,但是如果您坚持要走这条路,那么上面的说明同样适用.

For what it's worth, I agree with @TravisJ. This is a bad design, but if you insist on going down this path, then my notes above apply.

这篇关于MVC Ajax表单和浏览器后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆