Click here to Skip to main content
14,827,050 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to convert a JS array to a PHP array. I tried to send the value to the PHP page:

JavaScript
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': JSON.stringify(seatsReserved) });
console.log(seatsReserved.sort(function(a, b){return a-b}));
}
}


However, when I run

PHP
$seatsReserved = json_decode($_POST['seatsReserved']);

I get this error:

PHP
Notice: Undefined index: seatsReserved


How can I correctly pass the array to PHP?
Posted
Comments
Kornfeld Eliyahu Peter 19-Oct-14 9:45am
   
What seatsReserved contains? Can it be that it can not by converted to JSON?

1 solution

I would Google for that[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900