开发者

Problems Rendering Remote Events using JSONP in FullCalendar

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
});


For anyone reading this now, there is a much simpler approach because Fullcalendar will automatically add the events if it sees the callback in the URL.

So, your event sources can just look like:

$('#calendar').fullCalendar({
  eventSources: [
    "http://some.domain.com/api/events.json?callback=?",
    "http://another.domain.com/api/events.json?callback=?"
  ]
});

The important part is the callback=?. Normally you'd use callback=myspecialfunction but Fullcalendar will interpret the ? and automatically add the events.


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);
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜