I would like to convert a JS array to a PHP array. I tried to send the value to the PHP page:
var seatsReserved = [];
function reserve(seat) {
seat.setAttribute("class", "reserved");
var hasClass = seat.classList.contains('reserved');
if (hasClass) {
seatsReserved.push(parseInt(seat.innerHTML));
$.post('../index.php', {
'seatsReserved': seatsReserved
});
console.log(seatsReserved.sort(function(a, b) {
return a - b
}));
}
}
However, when I run
$seatsReserved = $_POST['seatsReserved'];
I get this error:
Notice: Undefined index: seatsReserved
How can I correctly pass the array to PHP?