javascript-fullcalendar-如何使用ajax加载日历上的所有事件
作者:互联网
我想在页面加载时使用Ajax在完整日历中加载所有事件.我收到Ajax的响应.但是该事件未添加到完整日历中.
这是我的jQuery代码
$('#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);
}
})
}
});
从我的控制台中,我发现一个错误,指出回调不是功能.请帮我,我是新手.
解决方法:
我认为您正在使本来应该很容易的事情变得非常复杂:我添加了一个JSFiddle Link,向您展示它是如何工作的.
$('#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);
}
});
});
标签:javascript,jquery,fullcalendar 来源: https://codeday.me/bug/20191013/1910055.html