返回 ajax 结果的按钮,建议请求

发布于 2024-12-24 20:18:24 字数 739 浏览 1 评论 0原文

我正在尝试解决我的应用程序中的后退按钮问题。场景是:

我有一个带有搜索表单的主页,它使用 $.ajax() 发送和接收数据,然后通过 ajax 加载结果,它们的链接指向一个控制器,该控制器不会由 ajax 中的 GET 完成,这样意味着页面将被刷新(因此结果主页如下所示: http://url/en/home< /a> 结果链接可能如下所示 http://url/fetch/data/x123av)。

问题是,当单击后退按钮从搜索框中返回结果时,解决该问题的最佳方法是什么?

我在 stackoverflow 中找到了一些与我的问题相关的答案: http://code.google.com/p/reallysimplehistory http://tkyk.github.com/jquery-history-plugin

但是从这些插件的文档来看,它们都是通过检查我没有的哈希更改来工作的。

希望我已经解释得足够好,并且我确实已经在 stackoverflow 和 google 上搜索了解决方案,但我没有找到与此接近的解决方案,或者我已经跳过了它......

请给我指出正确的方法: D

I am trying solve the back button issue within my app. The scenario is:

I have a home page with a search form which sends and receives data with $.ajax(), then the results loaded through ajax, their links points to a controller that won't be done by GET in ajax so that means that the page will be refreshed (so the home page with the results looks like this: http://url/en/home and a result link may look like this http://url/fetch/data/x123av).

The problem is which is the best way fix that when click back button to return the results from the search box?

I have found some answers in stackoverflow related to my question:
http://code.google.com/p/reallysimplehistory
http://tkyk.github.com/jquery-history-plugin

But from the documentation of those plugins, they all work by checking the hash change which I don't have.

Hope I have explained well enough, and I do have searched stackoverflow and google for a solution but I didn't find one that is close to this or either I've jumped over it...

Please just point me to the right way :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娜些时光,永不杰束 2024-12-31 20:18:24

但是从这些插件的文档来看,它们都是通过检查来工作的
我没有的哈希更改。

如果您想使用 AJAX 请求处理后退按钮,您将必须重新设计您的应用程序,以便它可以使用哈希,因为这是唯一的方法。更改 URL 的片段部分不会触发页面重新加载,但会添加到历史记录中,因此当您按下后退按钮时,您无需离开页面即可检测到此更改。

正如 SLaks 在评论部分中提到的,另一种可能性是使用 HTML5 历史记录 API 但显然这假设客户端浏览器支持它。

But from the documentation of those plugins, they all work by checking
the hash change which I don't have.

If you want to handle the back button with AJAX request you will have to redesign your application so that it works with hashes as that's the only way. Changing the fragment portion of an url doesn't trigger a page reload but it is added to the history, so when you press the back button you are able to detect this change without navigating away from the page.

As mentioned by SLaks in the comments section another possibility is to use the HTML5 history API but obviously this assumes that the client browser supports it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文