fullcalendar - 如何使用ajax加载日历上的所有事件 [英] fullcalendar - How to load all events on calendar using ajax

查看:114
本文介绍了fullcalendar - 如何使用ajax加载日历上的所有事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在页面加载时使用Ajax在完整日历中加载所有事件。我从Ajax获得响应,但事件未添加到完整日历中。
这里是我的jquery代码

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.

推荐答案

我认为你正在制作应该很容易看起来很复杂的东西:我已经添加了 JSFiddle Link 向你展示它是如何工作的。

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

});

这篇关于fullcalendar - 如何使用ajax加载日历上的所有事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆