I've been tearing my hair out at such a simple problem. I have the following JS array:
var orderDetailsArray = new Array();
orderDetailsArray[0] = 'test 1';
orderDetailsArray[1] = 'test 2';
orderDetailsArray[2] = 'test 3';
orderDetailsArray[3] = 'test 4';
Then I have the following Ajax code to send this array to a PHP file
$.ajax({
type: "POST",
url: 'http://testdomain.com/file.php',
data: JSON.stringify(orderDetailsArray),
contentType: "application/json",
success: function(data) {
alert(data);
}
});
In my PHP file I have the following
$orderDetailsArray = json_decode($_POST['orderDetailsArray']);
echo $orderDetailsArray[0];
But for some reason alert(data)
always just returns blank. I have no idea why this doesn't return the correct values.
Any help would be really great.
Thanks