fullcalendar js: fetching more events with ajax

前端 未结 3 1172
时光取名叫无心
时光取名叫无心 2020-12-18 17:13

I\'m using fullcalendar, how can I fetch more events from same server side, multiple urls? The initial one works, I just want to add additional events when they arrive(ajax)

3条回答
  •  心在旅途
    2020-12-18 17:57

    If each and every time you are using a different URL, then you can simply use addEventSource with the new URL.

    If you are attempting to use the same URL, you can get all events (old and new) using refetchEvents.

    You can also get the JSON and create the event as a client event using renderEvent. The latter is the most "ajax-y" of the options. In this case have your source return the JSON that represents the events, iterate through the array of new events, and call renderEvent on it.

    // this call goes in a poll or happens when the something should trigger a
    // fetching of new events
    $.ajax({
      url: "path/to/event/source",
      success: function(data){
          $.each(data, function(index, event)
                    $('#calendar').fullCalendar('renderEvent', event);
          );
      }
    });
    

提交回复
热议问题