Search code examples
phpjsonajaxfullcalendarfullcalendar-scheduler

How do I pass current date range from Fullcalendar to the JSON function


I use fullcalendar eventsources function, to get events data from db:

eventSources: getSources()

where getSources is

getSources(){
 var mysources = {
   mysourceone:{
                url: YOUR URL TO GET JSON,
                type: 'POST', 
                data:{
                    st:'2016-08-19',et:'2016-08-24'
                 },     
                 cache: false,
                 color: '#C1272D',
                 textColor: 'white'
                 }
              }
  return [mysources.mysourceone];
}

My question is, how do I replace fixed dates in this function with currently selected date range in fullcalendar?

                data:{
                    st:'2016-08-19',et:'2016-08-24'
                 }, 

Solution

  • FullCalendar should pass the start and end dates automatically, so just leave them out of your call, and on the page where FullCalendar checks for events you can just access $_GET['start'] and $_GET['end'] and query your database based on those dates. You can also go to your browser inspector and view the network tab while switching months, weeks or views on your calendar and see the calls it makes. You can also append your own variables like user id's, time zones and so on.