FullCalendar: how to display events in fullcalendar through ajax response

浪子不回头ぞ 提交于 2019-12-12 03:40:08

问题


I am working in full calendar. Now i need to show up all the events from the database through the ajax call. Till now , i have taken the events from database through json. My json output is as follows after the var_dump:

array (size=3)
  0 => 
    array (size=7)
      'title' => string 'hi' (length=2)
      'id' => int 1
      'start' => string '2016-05-30 00:00:00.000' (length=23)
      'rendering' => string 'background' (length=10)
      'backgroundColor' => string '#ff9999' (length=7)
      'className' => string 'event-full' (length=10)
      'textColor' => string 'white' (length=5)
  1 => 
    array (size=7)
      'title' => string 'vibrator' (length=8)
      'id' => int 3
      'start' => string '2016-05-26 00:00:00.000' (length=23)
      'rendering' => string 'background' (length=10)
      'backgroundColor' => string '#ff9999' (length=7)
      'className' => string 'event-full' (length=10)
      'textColor' => string 'white' (length=5)
  2 => 
    array (size=7)
      'title' => string 'vibrator' (length=8)
      'id' => int 8
      'start' => string '2016-05-26 00:00:00.000' (length=23)
      'rendering' => string 'background' (length=10)
      'backgroundColor' => string '#ff9999' (length=7)
      'className' => string 'event-full' (length=10)
      'textColor' => string 'white' (length=5)

and my script through my ajax is as follows:-

 events: function(start, end, timezone, callback)
{    
$.ajax({
        url: "calendar/show_events",
        type: 'POST', // Send post data
        data: 'type=fetch_events',
        async: true,

        success: function(s){

             dynamic_events =s;
                       alert(dynamic_events);
             // $('#calendar').fullCalendar('addEventSource', JSON.parse(dynamic_events));

              var dynamic_events = [];
                $(doc).find('event').each(function() {
                    events.push({
                        title: $(this).attr('title'),
                        start: $(this).attr('start') // will be parsed
                    });
                });
                callback(events);

              }
    });    
}

What is the error in my code.. I want to learn now. Can anyone help me and save my day. I am in need to display all the events in the FullCalendar. Thanks In Advance


回答1:


Change your ajax code to that

$.ajax({
    url: "calendar/show_events",
    type: 'POST', // Send post data
    data: 'type=fetch_events',
    async: true,

    success: function(s){

          var dynamic_events = [];
            $(s).find('event').each(function() {
                dynamic_events.push({
                    title: $(this).attr('title'),
                    start: $(this).attr('start') // will be parsed
                });
            });
            callback(dynamic_events);

          }
});    


来源:https://stackoverflow.com/questions/37481363/fullcalendar-how-to-display-events-in-fullcalendar-through-ajax-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!