FullCalendar事件(作为函数)没有填充

时间:2018-01-08 14:41:17

标签: javascript events fullcalendar

我尝试将现有解决方案集成到优秀的https://fullcalendar.io日历中,但我遇到了让事件出现的问题。我没有太多的网络开发经验,所以我希望答案很简单,这是我到目前为止的地方。

在' Agenda.aspx'页面,我按照文档

中的描述调用该函数



  $(document).ready(function() {

    $('#calendar').fullCalendar({
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay,listWeek'
      },
      defaultDate: '2017-12-18',
      navLinks: true, 
      editable: true,
      eventLimit: true, 

      events: function(start, end, timezone, callback) {
        $.ajax({
          type: 'POST',
          url: 'Agenda.aspx/GetEvents',
          dataType: 'json',
          data: "{'eventStart': " + start.unix() + ", 'eventEnd': " + end.unix() + "}",
          contentType: "application/json; charset=utf-8",
          success: function(doc) {
            var events = [];
            $(doc).find('event').each(function() {
              events.push({
                title: $(this).attr('title'),
                start: $(this).attr('start'),
                end: $(this).attr('end')
              });
            });
            callback(events);
          }
        });
      }
    })
  }); 




' GetEvents'是一个C#方法,它查询SQL数据库以获取该月的事件并返回一个json字符串:

        [WebMethod]
    public static string GetEvents(double eventStart, double eventEnd)
    {
        dbHandler m_dbHandler = new dbHandler();

        string JSONString;

        DateTime dt_eventStart = UnixTimeStampToDateTime(eventStart);
        DateTime dt_eventEnd = UnixTimeStampToDateTime(eventEnd);

        DataTable dtEvents = new DataTable();
        if (!m_dbHandler.GetCalendarEventsByDateRange(ref dtEvents))
        {
            throw new Exception("Error retrieving client tokens");
        }
        else
        {
            JSONString = string.Empty;
            JSONString = JsonConvert.SerializeObject(dtEvents);                               
        }

        return JSONString;
    }

该方法被调用,但事件不会被填充。如果我将方法调用替换为下面的json(这是c#方法返回的内容),则填充事件:

[{ "title": "Booking1", "start": "2017-12-18T09:00:00", "end": "2017-12-18T10:00:00" }, { "title": "Booking2", "start": "2017-12-18T09:00:00", "end": "2017-12-18T11:00:00" }, { "title": "Booking3", "start": "2017-12-18T10:00:00", "end": "2017-12-18T11:00:00" }, { "title": "Booking4", "start": "2017-12-18T12:00:00", "end": "2017-12-18T13:00:00" }, { "title": "Booking5", "start": "2017-12-18T10:00:00", "end": "2017-12-18T12:00:00" }]

以下是我从我的职能部门获取的指南中的页面: https://fullcalendar.io/docs/event_data/events_function/

任何帮助表示赞赏。

ajax调试: ajax debug screenshot

0 个答案:

没有答案