for some reason my event data isn’t working correctly with jquery fullcalendar when I load it via ajax. However, the ajax request is definitely returning correctly formatted JSON data – if i simply copy and paste the returned data and hard code it into the event source when initialising the calendar, all works correctly! Here is my code – any idea what the issue could be?
$(document).ready(function() {
// This is the data returned by the AJAX request - works fine when hard coded
var data =
[{"title":"Test Event","description":"<p>Tester<\/p>","start":"1329264000","end":"1329264000","className":"sport junior_school"}];
var cal = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
eventSources: [
'<?php echo Url::base()?>school-calendar/fetch_events'
//data
]
});
});
In the page you linked from the comment discussion, you are not using the code you showed in your post. In your actual page, you are setting a var named
datato the return value of your call to$.getJSON, and then passingdataintofullCalendaras an event source.The problem with that is that
$.getJSONreturns a jQXHR object, and fullCalendar cannot take such an object as a data source.In Firebug, if I empty your
#calendarelement and run the following, I get an event on the calendar:Or, if you really want to run your own AJAX call, then you need to pass data to the calendar in the success callback of the
$.getJSON. Here is one variation of such a thing:I see little benefit to the latter, however.