views:

43

answers:

2

to gather the value from the check boxes:

var filtersArray = $("input[@name='filters']:checked").map(function(i,n){
                        return $(n).val();
                    }).get();

Posting to php file

$.post("php/performSearch.php", {
     keywords: $('#keywords').val(), 
     'filters[]': filtersArray}, 
     function(data){
         //alert(data);
     });

Php doesn't get the array no matter what i do to it I have:

$postedKeywords = $_POST['keywords'];
$postedFilters = $_POST['filters[]'];

Keywords is posted, filters[] is not. I tried print_r....no result..

I tried:

foreach($_POST as $val)
    echo $val;

I get the value of $_POST['keywords'] and Array for $_POST['filters'] So it is sent but for some reason i cannot use the values.

+1  A: 

Have you tried:

$.post(
    'php/performSearch.php', {
        keywords: $('#keywords').val(), 
        filters: filtersArray
    }, 
    function(data) {

    }
);

This will send a POST request that might look like this:

filters[]=1&filters[]=2
Darin Dimitrov
that is the solution. thank you. I read some questions here and the solution for the same problem was putting some []. I guess i wasn't supposed to.
Hello, if you choose this as your solution, please check the box to accept it as an answer. And don't forget to give out a few points to people that have helped you as well. A 0% accept rate will make most people avoid answering your question, so avoid that and go back and accept answers to some of your older questions please :)
fudgey
Oh and check out the `jQuery.param()` helper function (http://api.jquery.com/jQuery.param/)
fudgey
A: 

Use this:

$.post("php/performSearch.php", {
     keywords: $('#keywords').val(), 
     'filters\[\]': filtersArray}, 
     function(data){
         //alert(data);
     });

Or try this too:

$.post("php/performSearch.php", {
     keywords: $('#keywords').val(), 
     filters: filtersArray}, 
     function(data){
         //alert(data);
     });

And to get in php, don't use [], just use:

$postedKeywords = $_POST['keywords'];
$postedFilters = $_POST['filters'];
Sarfraz