简体   繁体   English

将搜索条件添加到网址,但无法返回

[英]Adding search criteria to the url, but can't go back

I'm trying to get the parameters of my search criteria into the url so that it's possible to copy and paste the specific search. 我正在尝试将搜索条件的参数放入网址,以便可以复制和粘贴特定搜索。

Currently I have this: 目前我有这个:

 // Search criteria in the url
 var ready = function(e){
     $("#filterrific_filter").click(function(){
       $.get($("#filterrific_filter").attr("action"), $("#filterrific_filter").serialize(), null, "script");
       history.pushState(null, document.title, $("#filterrific_filter").attr("action") + "?" + $("#filterrific_filter").serialize());
       e.preventDefault();
     });
     $(window).bind("popstate", function() {
       $.getScript(location.href);
     });
 };
 $(document).ready(ready);
 $(document).on('page:load', ready);

The problem is: when a result is clicked on, and the users tries to go back to the search page again, they don't get back, they stay on the same page. 问题是:当点击结果,并且用户再次尝试返回搜索页面时,他们不会回来,他们会停留在同一页面上。 The url changes though. 网址发生了变化。

Here is a video to display the problem 这是一个显示问题的视频

And here is a link to the webpage, if you would like to test it yourself 如果您想自己测试,这里有一个指向该网页的链接

Thanks in advance! 提前致谢!

Try removing this whole section: 尝试删除整个部分:

$(window).bind("popstate", function() {
  $.getScript(location.href);
});

Since your apartments#show action (a guess, assuming you're using a RESTful design in your Rails backend) is a round-trip request (not AJAX, like your filter), and your query string URL will run the filterrific scripts correctly on a reload, you might as well let the back button work the default way. 由于您的apartments#show action(猜测,假设您在Rails后端使用RESTful设计)是往返请求(不是AJAX,就像您的过滤器一样),并且您的查询字符串URL将正确运行filterrific脚本重新加载,您可以让后退按钮以默认方式工作。

Disclaimer: this is a shot in the dark without more context. 免责声明:这是一个没有更多背景的黑暗镜头。 If it doesn't work for you, and you provide more context, I'll happily revisit. 如果它对您不起作用,并且您提供了更多背景信息,我将很乐意再次访问。

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

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