I\'ve been using Serialize() to pass checkbox form data with Post() for a basket that can hold multiple items of the same category.
When I post them using the submit
Jquery will take multi dimensional arrays directly, no need to serialize.
var data = {
foo: 123,
bar: 456,
rows: [
{
column1 : 'hello',
column2 : 'hola',
column3 : 'bonjour',.
},
{
column1 : 'goodbye',
column2 : 'hasta luego',
column3 : 'au revoir',
},
],
test1:{
test2: {
test3: 'baz'
}
}
};
_Post Data in your PHP file would look like this
Array
(
[foo] => 123
[bar] => 456
[rows] => Array
(
[0] => Array
(
[column1] => hello
[column2] => hola
[column3] => bonjour
)
[1] => Array
(
[column1] => goodbye
[column2] => hasta luego
[column3] => au revoir
)
)
[test1] => Array
(
[test2] => Array
(
[test3] => baz
)
)
)
Once you define your data multidimensional array, your Ajax could be as simple as
$.ajax({
type: 'post',
cache: false,
url: './ajax.php',
data: data
});
If your post array may have fields that you don't know about, you can access your Post array in your php file easily with
$data = file_get_contents('php://input');
$data = json_decode($data, true);