I use this PHP/CodeIgniter code to generate events on fullCalendar
$('#calendar').fullCalendar({
events: [
<?php foreach($cal_data as $row): ?>
{
title : '<?php echo $row->pt_name . ' ' . $row->value_2; ?>',
start : '<?php echo $row->date . 'T' . $row->time .'Z'; ?>',
url : '<?php echo base_url() . 'events/events_edit/' . $row->record_id; ?>',
color: '<?php echo $row->value_4; ?>'
}, // <=== this comma is the problem
<?php endforeach; ?>
],
etc...
As you can see on line 10 there is that final comma which will close the event data, and the loop goes on. A typical output will be:
events: [
{
title : 'Test1',
start : '2011-04-07T08:45:00Z',
url : http://example.com/events/events_edit/81',
color: '#ed9d2b'
},
{
title : 'Test2',
start : '2011-04-09T08:45:00Z',
url : http://example.com/events/events_edit/82',
color: '#ed9d2b'
}, // <======= trailing comma
Unfortunately the trailing comma from the last event breaks the render on IE8 (events show nicely on Cr, FF, Saf).
Any suggestions on how to resolve this problem?
It looks like you’re building JSON. Why not actually, say, build JSON? Alter your code to build a multi-dimensional array instead of output. You’d want a structure like
By building the data separately from emitting it, you can ensure you have it correct to begin with, and let the JSON encoder worry about the syntax: