简体   繁体   English

在 Fullcalendar V5 上使用 Ajax 从数据库中获取事件后未显示

[英]Events not displaying after fetching from database using Ajax on Fullcalendar V5

I am trying to fetch events from database using Ajax and then display it on FullCalendar Scheduler v5.6.0 , I can see that events are returned from database but not rendering.我正在尝试使用 Ajax 从数据库中获取事件,然后将其显示在FullCalendar Scheduler v5.6.0上,我可以看到事件是从数据库返回的,但没有呈现。 Here what i have tried so far.这是我到目前为止所尝试的。

document.addEventListener("DOMContentLoaded", function () {
  var calendarEl = document.getElementById('calendar');

var calendar = new FullCalendar.Calendar(calendarEl, {
  initialView: 'dayGridMonth',
  headerToolbar: {
    center: 'title',
    right: 'dayGridMonth,timeGridWeek,timeGridDay'
  },

    events: function (fetchInfo, successCallback, failureCallback) {
      jQuery.ajax({
        url:  "/getrecords",
        type: "GET",
 
        success: function (data) {
          var events = [];
          for (var i = 0; i < data.event.length; i++) {

            console.log(data.event[i].title); // It shows all event titles perfectly
               
          events.push({
          title: data.event[i].title,
          start: data.event[i].from_data,
          end: data.event[i].to_date, 
            });
          }
               console.log(events) // Here i have list of all events
        

          successCallback(events);
        },
      });
    },
  });
  calendar.render();
});

If i put static events in events objects it works fine,but not rendering while called from database using Ajax.如果我将 static 事件放在事件对象中,它可以正常工作,但在使用 Ajax 从数据库调用时无法渲染。 Any help would be highly appreciated.任何帮助将不胜感激。

Below is the console output.下面是控制台 output。

控制台输出

I achieved this by using this code on my project.我通过在我的项目中使用此代码实现了这一点。

var calendar = new FullCalendar.Calendar(calendarEl, {
  initialView: 'dayGridMonth',
  headerToolbar: {
    center: 'title',
    right: 'dayGridMonth,timeGridWeek,timeGridDay'
  },
    events: {
                url: encodeURI('/getrecords'),
                type: 'GET',
                color: 'red', // a non-ajax option
                textColor: 'white' // a non-ajax option
            }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM