MVC Ajax form and browser back button

天涯浪子 提交于 2019-12-13 01:26:51

问题


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.

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).

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 - 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.


回答1:


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

UPDATE

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.



来源:https://stackoverflow.com/questions/28747706/mvc-ajax-form-and-browser-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!