views:

44

answers:

1

I'm trying to load a json events feed into the FullCalendar jQuery plugin, however, I don't understand how to pass the data into FullCalendar. The url is called, and the JSON object is available inside the eventHandler function.

The code below attempts to pass the resulting data into a global variable (which, doesn't feel right), which is then passed into FullCalendar.

What is the right way to pass the data from the request into FullCalendar?

function eventHandler(data) {
    events = data;
}


$.ajax({
    dataType: 'jsonp',
    url: 'http://localhost:9393/events/calendar/1.json',
    jsonp: 'callback',
    success: eventHandler
});
+1  A: 

If you will be accessing the JSON on the same domain (when you deploy) then the following should work:

$('#calendar').fullCalendar({
  events: "http://localhost:9393/events/calendar/1.json"
});

Alternatively, you're looking at:

$.getJSON("http://localhost:9393/events/calendar/1.json&jsoncallback=?",
    function(data){
      $('#calendar').fullCalendar(data);
    });
t3hb4tman
So, should I be initiating fullCalendar inside the request block? If so, what about loading other event sources?
nickcharlton
According to the documentation, yeah. As far as loading other event sources it looks like you're going to delegate that to another function that makes your requests and merges all of the JSON objects into one JSON object holding all of your data. It looks like FullCalendar doesn't have native support for multiple event sources.
t3hb4tman
The final solution required adjusting the third line above, to specify what the data should do. `$('#calendar').fullCalendar({events: data});`
nickcharlton