简体   繁体   English

根据搜索过滤器修改URL

[英]Modify URL based on search filter

I have a product search page. 我有一个产品搜索页面。 In which I have search field. 我在其中搜索字段。 After searching the list of product is displaying in result section. 搜索后,结果列表中将显示产品列表。 Now I want to modify the search using left side panel "Refine your search" , in this section there are some parameter that will narrow your search. 现在,我想使用左侧面板“ Refine your search”修改搜索,在本节中,有一些参数可以缩小搜索范围。 Let user searching Shirt then my URL is http://localhost:8080/query?q=shirt Now if user refine the result with color RED. 让用户搜索衬衫,然后我的URL是http:// localhost:8080 / query?q = shirt现在,如果用户使用红色优化结果。 I need to update the URL with http://localhost:8080/query?q=shirt&color=red How to do ? 我需要使用http:// localhost:8080 / query更新URL ?q = shirt&color = red怎么办? I am using Spring MVC and JSP , Javascript is also an option. 我正在使用Spring MVC和JSP,也可以选择Javascript。

If you aren't adverse to using jQuery, then you can implement this. 如果您不反对使用jQuery,则可以实现这一点。 It doesn't completely account for the actual search query though since I don't fully know your implementation. 尽管我不完全了解您的实现,但它并未完全考虑实际的搜索查询。

var currentColor = '';

$("input[type=radio]").on('click', function () {
    var previousColor = currentColor;
    currentColor = $(this).val();

    //if the parameter has already been set then replace, otherwise create a new one
    if (previousColor) {
        location.href = location.href.replace("color=" + previousColor, "color=" + currentColor);
    } else {
        location.href = location.href + '&color=' + currentColor;
    }
});

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

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