Javascript 向fullcalendar请求添加自定义参数
我想将名为Javascript 向fullcalendar请求添加自定义参数,javascript,jquery,fullcalendar,Javascript,Jquery,Fullcalendar,我想将名为foo的参数添加到fullcalendar在检索事件数据时提交的请求中。根据这一点,可通过以下方式实现: var getFoo() = function() { // implementation omitted }; $('#calendar').fullCalendar({ loading: function(isLoading) { // CAN I SOMEHOW UPDATE foo FROM HERE? }, events
foo
的参数添加到fullcalendar在检索事件数据时提交的请求中。根据这一点,可通过以下方式实现:
var getFoo() = function() {
// implementation omitted
};
$('#calendar').fullCalendar({
loading: function(isLoading) {
// CAN I SOMEHOW UPDATE foo FROM HERE?
},
events: {
url: '/myfeed.php',
type: 'POST',
data: {
foo: getFoo()
}
}
});
我希望每次请求日历事件数据时都计算foo
参数的值,但fullcalendar似乎只在第一次加载时调用getFoo()
,然后在每次后续请求中重新使用该值
我曾尝试使用此函数加载数据之前立即触发的加载
事件,但我不知道如何在此函数中更新foo
参数
更新
我遵循了以下建议,并使其与此一起工作:
$('#calendar').fullCalendar({
events: function(start, end, callback) {
$.ajax({
url: 'getCalendarEvents',
dataType: 'json',
data: {
start: Math.round(start.getTime() / 1000),
end: Math.round(end.getTime() / 1000),
foo: getFoo()
},
success: function(doc) {
var events = eval(doc);
callback(events);
}
});
},
});
也许您可以使用创建自己的ajax请求
var getFoo() = function() {
// implementation omitted
};
$('#calendar').fullCalendar({
events: function(start, end, callback) {
var myFoo = getFoo();
$.ajax({
url: 'myxmlfeed.php',
dataType: 'xml',
data: {
// our hypothetical feed requires UNIX timestamps
start: Math.round(start.getTime() / 1000),
end: Math.round(end.getTime() / 1000),
foo: myFoo
},
success: function(doc) {
var events = [];
$(doc).find('event').each(function() {
events.push({
title: $(this).attr('title'),
start: $(this).attr('start') // will be parsed
});
});
callback(events);
}
});
}
});
尝试将lazyFetching设置为false。我猜您会遇到这个问题,因为fullCalendar试图将您从不必要的ajax请求中解救出来