Passing a multidimensional array to javascript via onClick event and sub-arrays are being read only as object
.
This is the json_encode
d array:
{
"products": {
"41::": {
"key": "41::",
"product_id": "41",
"name": "iMac",
"model": "Product 14",
"shipping": "1",
"image": "data/demo/imac_1.jpg",
"option": [],
"download": [],
"quantity": 3,
"minimum": "1",
"subtract": "1",
"stock": true,
"price": 100,
"total": 300,
"reward": 0,
"points": 0,
"tax_class_id": "9",
"weight": 15,
"weight_class_id": "1",
"length": "0.00000000",
"width": "0.00000000",
"height": "0.00000000",
"length_class_id": "1"
}
},
"token": "17263a44810f21b88362f908d2c4be02",
"customer_id": "1"
}
Which returns perfectly when json_decode
d in php, but in javascript via console.log(data):
{products: Object, token: "17263a44810f21b88362f908d2c4be02", customer_id: "1"}
The php:
`<a id="button-checkout" class="button" onclick='checkOut(<?php echo $json; ?>)'>
<span>Process Cart to Order</span></a>`
The javascript:
function checkOut(data) {
console.log(data);
return false;
}
Am I missing a step?