I have the following piece of jQuery code:
function saveSchedule()
{
var events = [];
$('ul#schedule-list').children().each(function() {
events.push($(this).attr('value'));
});
jQuery.each(events, function()
{
alert(this);
});
$.post("schedule_service.php?action=save_schedule",
{ events: events, studentid: $('#student').val() },
function(data) {
alert(data);
}, 'json');
}
Which gets all the 'values' from a list on my page, and puts them into the events array.
Then, below I pass in that array plus a studentid into the data section of my $.post call.
However, when I receive this array on my PHP side, it seems to be a singular value:
<?php
include_once('JSON.php');
$json = new Services_JSON();
if ($_GET['action'] == 'save_schedule')
{
$event_list = $_POST['events'];
echo $json->encode($event_list);
exit;
}
?>
(note: I'm using an older version of PHP, hence the JSON.php library.)
Now, all this ever returns is "14", which is the last event in the events array.
Post:
Response:
How am I handling passing the array in my $.post wrong?