dongyi2889 2019-05-10 11:15
浏览 105
已采纳

laravel:如何在fullcalendar中提供数据,从控制器中的数据库中获取

my Controller :

 public function eventCalender(){
    $eventCalender = [
        'title' => 'Matts Booking',
        'start' => '2019-05-05',
    ];
    $response = [
        'eventCalender'   => $eventCalender,
        'status'    => 1,
    ];
    return response()->json($response);
}


my js file :

function getEventCalender() {
    var actionurl = base_url + "/events/event-calender";
    $.ajax({
        type: "GET",
        url: actionurl,
        success: function (res) {
            if (res['status'] == 1) {
                $("#event-list").hide();
                $("#calender-list").show();
            } else {
                console.log("Something went wrong!!!!");
            }
        },
        error: function (jqXHR, exception) {
            $("#errormsg").show();
        }
    });
}
$(document).ready(function () {
    getEventCalender();
    document.addEventListener('DOMContentLoaded', function () {
        var calendarEl = document.getElementById('calendar');

        var calendar = new FullCalendar.Calendar(calendarEl, {

            plugins: ['interaction', 'dayGrid', 'list', 'googleCalendar'],

            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'dayGridMonth,listYear'
            },

            defaultDate: '2019-03-12',
            navLinks: true,
            businessHours: true,
            editable: true,
            event: res.eventCalender,

        });

        calendar.render();
    });
});

so this is my controller and js file what i want is when i get data from controller how do i print that data in calendar ?

and i am using fullcalendar so when i add

document.addEventListener('DOMContentLoaded', function () { }


this function then only my calendar show in page.
If i put above function out of getEventCalender() function then my calender show perfectly but when i put it in getEventCalender() function like shown above it doesn't show my calendar.

</div>
  • 写回答

1条回答 默认 最新

  • dtvhqlc57127 2019-05-10 11:27
    关注

    Call the getEventCalender() in a document ready function to execute after all the content has loaded

    $(function() {
       getEventCalender();
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化