FullCalendar: events not rendering initially from function call (AJAX)

别来无恙 提交于 2019-12-04 14:29:00

Instead of using your own ajax call, have you tried using fullcalendars?

http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/

Fullcalendar defaults the dataType as JSON and caching to false.

Combined some of your code with code from doc:

$('#calendar').fullCalendar({

    events: {
        url: 'http://localhost:8080/getEvents',
        type: 'GET',
        error: function() {
            alert('there was an error while fetching events!');
        },
        success: function(reply) {
            console.log(reply.first);
            callback(reply.first);
        },
        color: 'yellow',   // a non-ajax option
        textColor: 'black' // a non-ajax option
    }

});

You can try just getting your JSON string cutting and pasting in and see if you can render without ajax call

     events: [
     {
            end: 1392129000,
            id: "phil@google.com",
            room: "Sh1",
            start: 1392127200,
            title: "Phil - Google"
      }]

You can also process the response:

$('#myCalendar').fullCalendar({
...
   eventSources : [{
      url: 'myUrl',
      type: 'GET',
   },
   success: function(replyObject) {
      var results = [];
      var reply= replyObject.Results[0];
      for(var index in reply) {
         results.push(reply[index]);
      }
      return results;
    }
    }]
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!