我有一个页面显示未来 30 天的事件。当用户单击月视图中的下一个或当用户继续单击周/日视图中的下一个按钮超过 30 天时,如何刷新日历?
如果我在周视图中第五次单击下一步按钮,我在日历上看不到任何事件,因为我只有 4 周的事件。
我想通过 ajax 从服务器中提取数据并刷新日历。
这是我当前的代码:
在页面加载时,我这样称呼:
GetFutureMeetingsForTimeSpan(1, 30);
function GetFutureMeetingsForTimeSpan(startDaysFromNow, endDaysFromNow) {
var obMtgs;
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == '200') {
try {
var arrMtgs = new Array();
var meetingObjectArray = JSON.parse(xmlHttp.responseText);
var startTime = '', endTime = '';
var yr1 = 0, mo1 = 0, day1 = 0, hr1 = 0, min1 = 0;
var yr2 = 0, mo2 = 0, day2 = 0, hr2 = 0, min2 = 0;
for (var i = 0; i < meetingObjectArray.length; i++) {
obMtgs = new Object();
obMtgs.id = meetingObjectArray[i].ID;
obMtgs.title = meetingObjectArray[i].ExchangeResource.Subject;
obMtgs.start = new Date(yr1, mo1, day1, hr1, min1, 0);
obMtgs.end = new Date(yr2, mo2, day2, hr2, min2, 0);
arrMtgs.push(obMtgs);
}
//populate the calendar with events array
$('#calendar').fullCalendar({
defaultView: 'agendaWeek',
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
disableDragging: true,
disableResizing: true,
editable: true,
events: arrMtgs,
eventRender: function (event,element){
//code removed
},
eventClick: function (calEvent, jsEvent, view) {
//code removed
},
viewDisplay: function (view) {
//code removed
}
});
}
catch (e) {
alert('decode failed! msg=' + e.message);
}
}
else {
alert('Failed to get meetings! status=' + xmlHttp.status);
}
}
}
//load events from server via webservice using ajax
var url = server_part + "/Meeting/Schedule/Future/TimeSpan/";
url += "?startDaysFromNow=" + startDaysFromNow;
url += "&endDaysFromNow=" + endDaysFromNow;
url += "&APIKey=asjdasjdhhksajhd";
xmlHttp.open("GET", url, false);
xmlHttp.setRequestHeader("Accept", "application/json");
xmlHttp.send();
}