0

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

1
Contributor
1
Reply
8
Views
3 Years
Discussion Span
Last Post by hsakapandit
0
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){
    ...
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.