简体   繁体   中英

fullcalendar - How to load all events on calendar using ajax

I want to load all events in full calendar using Ajax when the page loads.I am getting response from Ajax.But the event is not added in Full calendar. here is my jquery code

$('#calendar').fullCalendar({
        theme: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        defaultDate: '2014-06-12',
        editable: true,
        events: function(start,end,callback){
            var mydata = {
                    action: "fw_ajax_callback",
                    subaction: "get_myappointments",

                };
                    $.ajax({
                    url :ajax_url,
                    type: 'POST',
                    data: mydata,
                    dataType: 'json',
                        success:function(appointments){
                            var events = [];
                            if(!!appointments){
                                $.map( appointments, function( r ) {
                                    events.push({
                                        title: r.title,
                                        start: r.start,
                                        end: r.start
                                    });
                                });
                            }
                            callback(events);
                        }

                })
        }
    });

From my console I found an error stating callback is not a function.Please help me i am a newbie.

I think you are making what is supposed to be easy look very complex: I have added a JSFiddle Link to show you how it work.

$('#calendar').fullCalendar({
        //theme: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        defaultDate: moment().format("YYYY-MM-DD"),
        editable: true,
        events: {
            url: 'http://www.json-generator.com/api/json/get/ccUKVDYErS?indent=2',
            error: function() {
                $('#script-warning').show();
            },
            success: function(){
                alert("successful: You can now do your stuff here. You dont need ajax. Full Calendar will do the ajax call OK? ");   
            }
        },
        loading: function(bool) {
            $('#loading').toggle(bool);
        }
    });

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM