javascript - FullCalendar:在模式弹出窗口上显示 ajax 调用事件

标签 javascript jquery ajax fullcalendar

我正在创建一个日程安排系统,我想使用 fullCalendar 显示每个用户的日程安排。我需要在引导模式中显示日历,并通过 AJAX 调用用事件填充日历。

我的问题是,当我单击按钮显示模式时,事件未显示在日历中。

enter image description here

我使用 Laravel 作为后端,这是从数据库检索时间表的代码

public function getTeacherScheduleAJAX($id){
    $schedule = DB::table('schedules AS s')
                ->select('s.lesson_name AS title','s.time_start AS start','s.time_end AS end')
                ->where('s.teacher',$id)
                ->get();
    return response()->json([
        'teacher' => $schedule
    ]);
}

这是我通过 AJAX 调用实现的方法

$('.btn-calendar').click(function() {
    $.ajax({
        url : '/teacher-schedule/'+$(this).data('teacherid'),
        type: 'GET',
        success: function(response){
            $('.calendar').fullCalendar('renderEvent', response.teacher, true);
            $('#scheduleModal').modal('show');              
        },
        error: function(err){
            console.log(err)
        }
    })
});

我在页面加载时初始化了它

$('.calendar').fullCalendar({
    header : {
        left:   'prev,next today',
        center: 'title',
        right:  'month,agendaWeek,agendaDay'
    },
    defaultView : 'agendaWeek',
    allDaySlot : false,
    eventOverlap: false
});

我从后端收到回复,只是它没有显示在日历中。

查询的响应

{
"teacher": [
    {
        "title": "English Lesson Schedule",
        "start": "2017-09-08 10:00:00",
        "end": "2017-09-08 12:00:00"
    },
    {
        "title": "English Lesson Schedule",
        "start": "2017-09-13 07:00:00",
        "end": "2017-09-13 09:00:00"
    }
  ]
}

最佳答案

要呈现多个事件,请使用

$('.calendar').fullCalendar('renderEvents', response.teacher, true); 

而不是

$('.calendar').fullCalendar('renderEvent', response.teacher, true); 

renderEvent 用于单个事件。

关于javascript - FullCalendar:在模式弹出窗口上显示 ajax 调用事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46080455/

相关文章:

javascript - .toggle() 问题与 jquery

javascript - 如何在 JQuery 中单击单选按钮后追加一个部分?

javascript - Highcharts 多线图

javascript - 在 AJAX 调用时将 jQuery 对象转换为字符串

jquery - 发布后使用 Jquery 更改按钮上的文本

javascript - 在数据改变时在knockout Change Paging

javascript - 如何让 service worker 只在第一次访问时注册?

javascript - 如何将文件附加到文件输入字段

ruby-on-rails - 防止用户发布虚假的 AJAX 请求(确保 AJAX 请求仅来自应用程序)

javascript - mysql中根据id更改图片