Php 将JSON中的事件添加到fullcalendar
我正在尝试使用json字符串将事件添加到我的fullcalendar日历中。这是我的密码:Php 将JSON中的事件添加到fullcalendar,php,arrays,json,fullcalendar,Php,Arrays,Json,Fullcalendar,我正在尝试使用json字符串将事件添加到我的fullcalendar日历中。这是我的密码: viewRender: function(view, element){ $.ajax({ url: 'http://www.example.com/get-events-json.php', type: 'POST', success: function (data) { $('#ca
viewRender: function(view, element){
$.ajax({
url: 'http://www.example.com/get-events-json.php',
type: 'POST',
success: function (data) {
$('#calendar').fullCalendar('addEventSource', data);
},
fail: function() {
alert('There was an error while fetching events.');
}
});
}
});
在我的success
中,数据是:
[{"title":"John Bobby","start":"2017-05-16T15:30:00","end":"2017-05-16T15:30:00"},{title":"Jason Kaple","start":"2017-05-20T17:30:00","end":"2017-05-20T17:30:00"}]
我尝试使用$('#calendar').fullCalendar('addEventSource',data)添加它代码>如您所见,但我在控制台中收到一条错误消息:
(数据)…]404(未找到)
我怎样才能解决这个问题?有什么办法可以解决这个问题吗?谢谢,您还可以通过ajax调用获取数据,并在渲染后使用addEvent添加元素
function addEvent(title, date){
calendar.addEvent({
title: title,
start: date,
allDay: true,
color: 'green'
});
}
for(event of events){
addEvent(event.title, event.date)
}
为什么不使用该属性?@Mikey我将如何将它用于我的数据字符串而不是url?为什么要这样做?如果通过以下方法指定事件提要:或通过基于日期更新事件的自定义函数:指定事件提要,则无论何时呈现视图和/或更改日期,事件都将自动刷新。在viewRender事件期间无需执行任何操作。您问:“我如何将其用于我的数据字符串而不是url?”,您不会,您将使用url,它将自动将数据
直接返回到fullCalendar。