1

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.

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

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.
Oh and check out the jQuery.param() helper function (api.jquery.com/jQuery.param)
0

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'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.