fullcalendar - How to load all events on calendar using ajax

喜欢而已 提交于 2019-12-02 08:51:09

问题


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.


回答1:


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);
        }
    });

});


来源:https://stackoverflow.com/questions/25444930/fullcalendar-how-to-load-all-events-on-calendar-using-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!