1

SOLVED

This is my whole ajax response:

{
    "data": [
        {
            "id": 3,
            "calendar_id": 1,
            "title": "asdasd",
            "start": "2017-06-20 14:06:00",
            "end": "2017-06-20 16:06:00",
            "allDay": 0,
            "className": "bg-green",
            "deleted_at": null
        }
    ]
}

Definition:

$('#calendar').fullCalendar({
    slotDuration: //..
    minTime: //...
    maxTime: //..
    defaultView: //...
    defaultDate: //..
    header: {
        //...
    },
    eventSources: [
         {
            url: '/api/calendar_events/' + id,
            type: 'GET',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            error: function () {
                alert('there was an error while fetching events!');
            }
        }
    ],
    eventLimit: //..
    selectable: //..
});

What is wrong in EventSources? The fullcalendar is rendered, but no events are displayed.

Note: I want to use eventSources not events because there can be more than one sources.

1 Answer 1

1

Did this:

eventSources: [
    {
        events: function (start, end, timezone, callback) {
            $.ajax({
                url: '/api/calendar_events/' + id,
                type: 'GET',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }, success: function (response) {
                    var events = [];
                    $(response['data']).each(function () {
                    events.push({
                        id: $(this).attr('id'),
                        title: $(this).attr('title'),
                        start: $(this).attr('start'),
                        end: $(this).attr('end'),
                        className: $(this).attr('className'),
                        allDay : $(this).attr('allDay'),
                    });
                });
                callback(events);
            }
        });
    }
    }
],

Not the answer you're looking for? Browse other questions tagged or ask your own question.