复选框过滤搜索结果

时间:2011-12-06 11:28:34

标签: php jquery filtering checkbox

我需要像这样过滤我的结果:

http://www.babycarers.com/search?searchref=12935259587085&specreq=all&postcode=Postcode%2FZip+%28optional%29&country=CA&searchbutton.x=38&searchbutton.y=12

我知道我必须在Ajax上使用jQuery。我找到了一些这样的例子:

http://jsfiddle.net/mattball/d2v4Q/

我不想玩能见度。我想使用PHP脚本过滤和解析用户的选择。

1 个答案:

答案 0 :(得分:0)

我不知道数据库的确切架构,但您要做的是使用

http://api.jquery.com/change/

检测复选框选择的更改,然后使用

http://api.jquery.com/jQuery.ajax/

并将所有参数传递给单独的.php文件,以便将结果从另一个页面中删除并打印出来

所以,一个例子。

<select class="order">
    <option value="name">Name</option>
    <option value="date_poster">Date Posted</option>
</select>

<div id="results">
</div>

<script>
    $("select.order").change(function(){
        var orderBy = $(this).val();
        $.ajax({
          url: "your_external_file.php",
          data: "orderBy="+orderBy,
          success: function(html){
            $("#results").append(html);
            //Add whatever you want to do here.
          }
        });
    });
</script>

虽然我没有测试过,但只要你正确命名文件就可以了。

相关问题