Javascript 从选择菜单更改更新HTTP GET请求

Javascript 从选择菜单更改更新HTTP GET请求,javascript,php,jquery,html,twitter-bootstrap,Javascript,Php,Jquery,Html,Twitter Bootstrap,我在PHP站点中有一个搜索结果页面,它返回一个结果列表。我现在需要在搜索结果页面中添加一个过滤器选项,以便用户可以从一些选择菜单选项中进一步优化搜索结果。搜索结果的URL如下所示: findProducts.php?action=searchAssets&orderNumber=xxxx&productName=zzz 并从搜索表单页面上的GET请求执行 我使用如下选择菜单添加了一些过滤器: findProducts.php?action=searchAssets&or

我在PHP站点中有一个搜索结果页面,它返回一个结果列表。我现在需要在搜索结果页面中添加一个过滤器选项,以便用户可以从一些选择菜单选项中进一步优化搜索结果。搜索结果的URL如下所示:

findProducts.php?action=searchAssets&orderNumber=xxxx&productName=zzz
并从搜索表单页面上的GET请求执行

我使用如下选择菜单添加了一些过滤器:

findProducts.php?action=searchAssets&orderNumber=xxxx&productName=zzz
过滤 按产品类型 汽车 火车 飞机
将on chage事件附加到下拉列表中,然后在触发时将其值附加到当前url,然后重新加载页面

$(document).ready(function(){
    $('#productType').change(function(){
        window.location.href = window.location.href + '&productType=' + $(this).val();
    });
});

在选择更改事件时,您可以调用一个函数,该函数将对您的搜索结果url进行ajax调用。。像这样:

findProducts.php?action=searchAssets&orderNumber=xxxx&productName=zzz
$productType.on'change',函数{

var product_type = $(this).val(); //selected product type
var your_search_url = "path/to/findProducts.php?action=searchAssets&orderNumber=xxxx&productName=zzz&productType="+product_type;
$.get(your_search_url, function(data, status){  
   // your code here to deal with the search results
});
})

这就是你需要的


你甚至可以做链式下拉列表。如果您想发送多个参数来执行某个操作,而php页面上的class='a'和b='c'使用了隐藏的表单feilds和javascript。

我在控制台中遇到了这个错误:运算符'='的左侧必须是一个引用。对于脚本窗口中的第三行。location.href=window.location.href+'&productType='=$this.val;对不起,我键入了..=$这个.val',它应该在哪里…+$这个.val;。更新了我的答案,你能再试一次吗?