I have arrays and variables in JQuery and I want to know that Can I POST both arrays and variables from single $ajax jquery request to my php page. If yes then How will I post data from Jquery and how will i handle in PHP page.

var get_id = [], get_product= [];  //Array
    var day = $("#day").val();  // Variable
    var month = $("#month").val(); // Variable
    var year = $("#year").val();   // Variable

Thanks

var data = {
    get_id : get_id,
    get_product : get_product,
    day : day,
    month : month
};

$.post('url', { data : JSON.stringify(data) }, function(response){
    // success
});

On the PHP side:

$data = json_decode($_POST['data']);

echo $data->day;
foreach($data->get_product as $p){
    ...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.