javascript - Fullcalendar: how to get events from two variables and pass to through 'eventAfterRender'? -


i have 2 types of events , namely 'holidays' , 'events', should received 2 variables. variables holding ajax responses. want pass holidays , events calendar 'events'. not know how pass variables. following ajax code, declared variable. code correct?

var return_holidays = function() {  var holdays = []; $.ajax({         url: "/calendar/show_holidays",         type: 'post', // send post data         data: 'type=fetch',         async: true,          success: function(s)             {            //alert(s);               holdays = s;               }     });     return holdays; }();     var return_events = function() { var dynamic_events = [];     $.ajax({         url: "calendar/show_events",         type: 'post', // send post data         data: 'type=fetch_events',         async: true,           success: function(s)          {//alert(s);          dynamic_events = s;           }     });     return dynamic_events; }();        $('#calendar').fullcalendar({   utc: true,  header: {  left: 'prev,next today',  center: 'title',  right: 'month,agendaweek,agendaday'  },  editable: true,  droppable: true,  eventsources: [return_holidays, return_events],//am calling variables eventafterrender: function(event, element, view) {  element.append(event.title);  }   }); 

can achieve in way? correct?

the return type of return_holidays, return_events should json, try returning json.stringify(yourarray); instead of plain array. try letting calendar deal fetching business:

$('#calendar').fullcalendar({      eventsources: [          {             url: '/calendar/show_holidays',             type: 'post',             data: {                 'type' : 'fetch'             },             error: function() {                 alert('there error while fetching holidays!');             },         },         {             url: '/calendar/show_events',             type: 'post',             data: {                 'type' : 'fetch_events'             },             error: function() {                 alert('there error while fetching events!');             },         }     ] }); 

http://fullcalendar.io/docs/event_data/events_json_feed/

alternatively can pass urls directly calendar:

$('#calendar').fullcalendar({     eventsources: [         '/calendar/show_holidays',         'calendar/show_events'     ] }); 

http://fullcalendar.io/docs/event_data/eventsources/

always make sure retuning objects in json format backend.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -