0

I've been trying to get events as an array for FullCalendar with ajax. Object array comes from back-end and i push the data in an array. But events doesn't show and there is no error. Interesting thing is; if i use break point on return array; line or $('#calendar').fullCalendar({ line(please check it out) then push continue, it works. I don't know what's going on. So i need some help. Here is my code:

$(document).ready(function () {
        var eventArray = [];

        eventArray = GetEvents();

        $('#calendar').fullCalendar({
            weekends: false,
            header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,basicWeek,basicDay,listMonth'
            },
            eventSources:
            [{
                events:eventArray,
                color: 'blue'
            }]                
        });
    });

    function GetEvents()
    {
        var array = [];

        $.ajax({
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json',
            url: 'Schedule.aspx/GetAuditDates',
            data: '{}',
            success: function (result) {
                $.each(result.d, function (k, v) {
                    array.push({ start: v.start ,title: v.title });
                });
            }
        });
        return array;
    }

Thanks in advance.

Flardryn
  • 457
  • 1
  • 10
  • 25
  • @Andreas But my array returns? I don't need return the data from ajax. I declared array, manupulated it in success and returned it in function. And i can see the result when debug it (it returns that array). Can you explain that why my question and that question are similar? – Flardryn Mar 24 '17 at 08:56
  • Just read the accepted answer and the links mentioned in the answer (tl;dr: `return array;` is executed **before** the `success` handler) – Andreas Mar 24 '17 at 09:00
  • @Andreas Oh i see now thank you – Flardryn Mar 24 '17 at 09:46

0 Answers0