I have this jQuery $.ajax script:
var data = JSON.stringify( selected_products );
$.ajax({ type: "POST",
url: "addtocart.php",
data: data,
dataType: 'application/json'
});
And I am posting this to a really simple PHP script:
$selected_products = json_decode($_POST['data'], true);
print_r($selected_products);
This is an example of what I'm sending; this is outgoing data in Chrome DevTools:
data:[{"id":"RECOLOURBALM","option":"Black","quantity":1},{"id":"TOWELS","quantity":1}]
However this is the console readout for the response:
Array
(
)
I think the request is succeeding and data is being passed, but the responses are all empty.
What am I doing wrong?