Reputation: 299
I have this code :
$('#calendar_1').fullCalendar({
header :
{
left : 'prev,next today',
center : 'title',
right : 'month,agendaWeek,agendaDay'
},
defaultView : 'month',
eventSources: [
{
url: 'holidays.php',
type: 'POST',
data : {
sdate : $("#calendar_1").fullCalendar('getView').intervalStart,
common : 'Common'
},
error: function() {
alert('there was an error while fetching events!');
},
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
}
],
eventRender : function(event, element, view) {
var date = event.start.format("YYYY-MM-DD");
$(view.el[0]).find('.fc-day[data-date='+ date +']').css('background-color','#FAA732');
}
});
Now this is what I get by print_r($_POST) :
Array
(
[common] => Common
[start] => 2017-12-31
[end] => 2018-02-11
)
As you can see There is no 'sdate' in result. Yes, I have 'start' in my result but that is first day visible in calendar not first day of the month. So, anyone can help me how to post that ?
Upvotes: 1
Views: 61
Reputation: 62078
As per fullCalendar's suggested methodology, you ought to be using the automatically provided start
and end
parameters to delimit the data sent by your server anyway, no need for the other date. Then if you have other views with differing time periods such as week or day, or some custom view with a smaller/larger visible range, it will fetch the exact data necessary for those specific dates.
Anyway, your sdate
value isn't transmitted because the data
object you supply is completely static. fullCalendar ingests it when the calendar is initialised and then keeps it like that. You gave an object, not code to be re-run, so it can't check the start date again when making the ajax request. At that moment I think there will be no intervalStart date for the view because it's not initialised.
If you really want to do something like this kind of dynamic value then you have to supply a callback function which fullCalendar can actually execute on every request and build an object dynamically.
data: function() { // a function that returns a new object dynamically for every ajax request, instead of a static object
return {
sdate : $("#calendar_1").fullCalendar('getView').intervalStart,
common : 'Common'
};
}
However because of the particular value you want to use, you'll still have trouble with this the first time your calendar loads, because the view will not be rendered when the ajax request starts and you won't have access to its properties including intervalStart - they will be null. And on subsequent runs, the view will not yet have changed, and the intervalStart value you'll get will be the one for the month you're moving away from. I do not think this is actually a viable approach, to be honest. See http://jsfiddle.net/sbxpv25p/88/ for a demo which will show you the problem.
Much of this is documented and demonstrated here: https://fullcalendar.io/docs/event_data/events_json_feed/
Upvotes: 1