0

I'm trying to send a multidimensional array to my PHP Webservice. As you can see in the console logs, the normal variable test2 is send successful, but my array is not transferred to my server. What am I doing wrong?

JavaScript:

function filter() {
    var filters = [];
    filters["f1"] = $("#filter-select").val() || [];

    console.log("Filters Array:")
    console.log(filters);

    $.post("/service/test",{test : filters, test2 : "test"},function(data){
        console.log("Webservice Response:");
        console.log(data);
    })

}

PHP:

var_dump($_POST);
die();

Console:

Filters Array:
[f1: Array[1]]
Webservice Response: 
array(1) {
  ["test2"]=>
  string(4) "test"
}
jussi
  • 2,166
  • 1
  • 22
  • 37
  • you can't send an array over post... you need to convert it to a string first... i would use in javascript JSON.stringify(filters) .. then in php json_decode($_POST['test']) – cocco Jul 25 '13 at 09:10

1 Answers1

0

First of all as mentioned by cocco in the comments I needed to use JSON.stringify, but it would return an empty array.

I used var filters = {}; for generating an object.

jussi
  • 2,166
  • 1
  • 22
  • 37