答案:錯誤不在同步或異步調用中,而是在使用由fullcalendar設置的函數中。 事件:功能(開始,結束,時區,回調){...}JS,fullcalendar,「events」參數沒有得到執行函數的結果
我能看到的信息轉換如何管理AJAX(sjax ...)的結果,但日曆沒有得到信息。
看起來這行「events:getJSON」不起作用。但功能是呼籲
現在,我有一個新的問題,函數getJSON從webmethod獲取JSON,但日曆不顯示它們。
我試圖用評論代碼也得到結果,但它不起作用。
這裏有兩種方法櫨的JS:
function getJSON() {
start = $('#calendar').fullCalendar('getDate').format();
duration = $('#calendar').fullCalendar('getCalendar').moment().format();
alert(start);
var retour;
$.ajax({
async: false,
type: 'POST',
url: "ConsultationPlanning.aspx/getPlanning",
data: '{"start": "' + start + '", "end": "' + duration + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
retour = JSON.parse(msg.d);
retour = msg.d;
},
error: function() { alert("erreur");}
});
alert(retour);
return retour;
};
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
hiddenDays: [0],
defaultView: 'agendaWeek',
editable: false,
allDaySlot: false,
selectable: false,
events: getJSON,
/*function (start, end, callback) {
start = $('#calendar').fullCalendar('getDate').format();
duration = $('#calendar').fullCalendar('getCalendar').moment().format();
$.ajax({
type: 'POST',
url: "ConsultationPlanning.aspx/getPlanning",
data: '{"start": "' + start + '", "end": "' + end + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var rdv = [];
alert(msg.d);
//var events =JSON.parse(msg.d);
$(msg.d).each(function() {
rdv.push({
id: $(this).attr('id'),
title: $(this).attr('title'),
start: $(this).attr('start'),
})
})
alert("first date : " + rdv[0].start);
//"first date: 2015-05-06T14:33:00" is what i get
callback(rdv);
//the callback generate an error message. it says, it's waiting for a function
}
})
}
});
我張貼了類似的問題,前幾天,但它與其他實現:
fullcalendar doesn't show events
它會工作,請參閱我的答案在這個問題上 http://stackoverflow.com/questions/30092190/populating-events-in-full-calender-javascript -from-the-database/30092608#30092608 – Sherlock
將它稱爲函數events:getJSON() – Sherlock
當我用圓括號調用函數時,我無法使用「$('#calendar')。fullCalendar('getDate') 。格式();」函數getJSON – Olivier