Pull data for next / previous months

I transfer my Fullcalendar data for the month that is being viewed. When I click the "Next / Prev Month" view buttons, it does not exit and retrieves new data for the new month.

How do I get the Next / Prev buttons to make another call to the database and display records for this month?

+3
source share
3 answers

Define an event callback to make an ajax request to your api. See here here . Here is an example of integration with my api that uses the beginning and end of an era as getting parameters in a search.

$('#calendar').fullCalendar({
    // other options here...

    events: function(start, end, callback) {
        start = start.getTime()/1000;
        end = end.getTime()/1000;
        $.ajax({
            url: '/api/events/1/?start='+ start + '&end=' + end,
            dataType: 'json',
            success: function(doc) {
                var my_events = [];
                $.each(doc.person.events, function (index, elem) {
                   my_events.push({
                       title: elem.event.title,
                       start: elem.event.start,
                       end: elem.event.end,
                   });
                });
            callback(my_events);
          }
        });
    }
});

( ) ajax. , fullcalendar json feed, , . :

$('#calendar').fullCalendar({
    events: "/api/events/1/"
});

api- , http://yourwebsite.com/api/events/1/?start=123454444&end=12355324234, , .

. , "1" URL- .

docs fullcalendar , , .

+3

, , . , json feed, , .

json, fullcalendar , . , , /.

0

Source: https://habr.com/ru/post/1759204/


All Articles