无法使用Laravel在Javascript FullCalendar中获取事件

无法使用Laravel在Javascript FullCalendar中获取事件,javascript,ajax,laravel,fullcalendar,fullcalendar-3,Javascript,Ajax,Laravel,Fullcalendar,Fullcalendar 3,我正在开发的系统中有一个页面需要有一个FullCalendar。用户将查看、添加、更新该日历中的任务或事件 我不知道发生了什么,我无法显示存储在数据库中的事件 我正在使用运行在Laravel6.3.0中的Sqlite数据库 参考代码见下文 完整日历生成 $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

我正在开发的系统中有一个页面需要有一个
FullCalendar
。用户将查看、添加、更新该日历中的任务或事件

我不知道发生了什么,我无法显示存储在数据库中的事件

我正在使用运行在Laravel6.3.0中的Sqlite数据库

参考代码见下文

完整日历生成

  $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            var calendar = $('#calendar').fullCalendar({
                editable: true,
                events: "{{url('/home')}}",
                displayEventTime: true,
                editable: true,
                eventRender: function (start, end,event, element, view) {
                    if (event.allDay === 'true') {
                        event.allDay = true;
                    } else {
                        event.allDay = false;
                    }
                },
                selectable: true,
                select: function (start, end, allDay) {
                    var start_date = moment(start, 'DD.MM.YYYY').format('YYYY-MM-DD');
                    var end_date = moment(end, 'DD.MM.YYYY').format('YYYY-MM-DD');
                    $('#createTask').modal('show');
                    $('#saveTaskBtn').click(function () {
                        title = $('#taskTitle').val();
                        description = $('#taskDescription').val();
                        var post_data = "name="+title+"&description="+description+"&start_date="+start_date+"&end_date="+end_date;
                        // var post_data = {
                        //     name:title,
                        //     description: description,
                        //     start_date: start_date,
                        //     end_date: end_date
                        // };

                        $.ajax({
                            url: "{{url('home/create')}}",
                            data: post_data,
                            type: "POST",
                            success: function (data) {
                                displayMessage("Added Successfully");
                            },
                            error : function (data) {
                                console.log(data);
                            }
                        });
                        calendar.fullCalendar('renderEvent',
                            {
                                title: title,
                                start: start_date,
                                end: end_date,
                                allDay: allDay
                            },
                            true
                        );
                        calendar.fullCalendar('unselect');
                    });
                }
});
路线

TasksController-
$data
在视图中传递了值

 public function index()
    {
        if (request()->ajax()) {
            $start = (!empty($_GET["start_date"])) ? ($_GET["start_date"]) : ('');
            $end = (!empty($_GET["end_date"])) ? ($_GET["end_date"]) : ('');

//            $data = Task::whereDate('start_date', '>=', $start)->whereDate('end_date', '<=', $end)->get(['id', 'title', 'description', 'start_date', 'end_date']);

            $data = Task::all();
            dd(Response::json($data));
            return Response::json($data);
        }

        return view('home');
    }

请阅读此处事件对象的规范:。表示开始日期和结束日期的属性所需的名称是什么?它们是否与您在JSON中使用的匹配?我想你很快就会看到答案是“不”。始终确保彻底检查文档。@ADyson是!我完全错了,很抱歉。我注意到当我遵循文档时。谢谢你的回答!干杯不用担心,很高兴它帮助了你
 public function index()
    {
        if (request()->ajax()) {
            $start = (!empty($_GET["start_date"])) ? ($_GET["start_date"]) : ('');
            $end = (!empty($_GET["end_date"])) ? ($_GET["end_date"]) : ('');

//            $data = Task::whereDate('start_date', '>=', $start)->whereDate('end_date', '<=', $end)->get(['id', 'title', 'description', 'start_date', 'end_date']);

            $data = Task::all();
            dd(Response::json($data));
            return Response::json($data);
        }

        return view('home');
    }
JsonResponse {#279
  #data: "[{"id":1,"name":"TEST","description":"TEST","start_date":"2019-11-02","end_date":"2019-11-03","created_at":null,"updated_at":null},{"id":2,"name":"TEST","description":"TEST","start_date":"2019-12-07","end_date":"2019-12-08","created_at":null,"updated_at":null},{"id":3,"name":"TEST","description":"TEST","start_date":"2019-11-02","end_date":"2019-11-03","created_at":null,"updated_at":null},{"id":4,"name":"TEST","description":"TEST","start_date":"2019-11-08 00:00:00","end_date":"2019-11-09 00:00:00","created_at":null,"updated_at":null}]"
  #callback: null
  #encodingOptions: 0
  +headers: ResponseHeaderBag {#290
    #computedCacheControl: array:2 [
      "no-cache" => true
      "private" => true
    ]
    #cookies: []
    #headerNames: array:3 [
      "cache-control" => "Cache-Control"
      "date" => "Date"
      "content-type" => "Content-Type"
    ]
    #headers: array:3 [
      "cache-control" => array:1 [
        0 => "no-cache, private"
      ]
      "date" => array:1 [
        0 => "Mon, 25 Nov 2019 11:50:48 GMT"
      ]
      "content-type" => array:1 [
        0 => "application/json"
      ]
    ]
    #cacheControl: []
  }
  #content: "[{"id":1,"name":"TEST","description":"TEST","start_date":"2019-11-02","end_date":"2019-11-03","created_at":null,"updated_at":null},{"id":2,"name":"TEST","description":"TEST","start_date":"2019-12-07","end_date":"2019-12-08","created_at":null,"updated_at":null},{"id":3,"name":"TEST","description":"TEST","start_date":"2019-11-02","end_date":"2019-11-03","created_at":null,"updated_at":null},{"id":4,"name":"TEST","description":"TEST","start_date":"2019-11-08 00:00:00","end_date":"2019-11-09 00:00:00","created_at":null,"updated_at":null}]"
  #version: "1.0"
  #statusCode: 200
  #statusText: "OK"
  #charset: null
  +original: Collection {#292
    #items: array:4 [
      0 => Task {#293
        #fillable: array:4 [
          0 => "name"
          1 => "description"
          2 => "start_date"
          3 => "end_date"
        ]
        #table: "tasks"
        #connection: "sqlite"
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:7 [
          "id" => "1"
          "name" => "TEST"
          "description" => "TEST"
          "start_date" => "2019-11-02"
          "end_date" => "2019-11-03"
          "created_at" => null
          "updated_at" => null
        ]
        #original: array:7 [
          "id" => "1"
          "name" => "TEST"
          "description" => "TEST"
          "start_date" => "2019-11-02"
          "end_date" => "2019-11-03"
          "created_at" => null
          "updated_at" => null
        ]
        #changes: []
        #casts: []
        #dates: []
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #guarded: array:1 [
          0 => "*"
        ]
      }
      1 => Task {#294
        #fillable: array:4 [
          0 => "name"
          1 => "description"
          2 => "start_date"
          3 => "end_date"
        ]
        #table: "tasks"
        #connection: "sqlite"
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:7 [
          "id" => "2"
          "name" => "TEST"
          "description" => "TEST"
          "start_date" => "2019-12-07"
          "end_date" => "2019-12-08"
          "created_at" => null
          "updated_at" => null
        ]
        #original: array:7 [
          "id" => "2"
          "name" => "TEST"
          "description" => "TEST"
          "start_date" => "2019-12-07"
          "end_date" => "2019-12-08"
          "created_at" => null
          "updated_at" => null
        ]
        #changes: []
        #casts: []
        #dates: []
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #guarded: array:1 [
          0 => "*"
        ]
      }
      2 => Task {#295
        #fillable: array:4 [
          0 => "name"
          1 => "description"
          2 => "start_date"
          3 => "end_date"
        ]
        #table: "tasks"
        #connection: "sqlite"
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:7 [
          "id" => "3"
          "name" => "TEST"
          "description" => "TEST"
          "start_date" => "2019-11-02"
          "end_date" => "2019-11-03"
          "created_at" => null
          "updated_at" => null
        ]
        #original: array:7 [
          "id" => "3"
          "name" => "TEST"
          "description" => "TEST"
          "start_date" => "2019-11-02"
          "end_date" => "2019-11-03"
          "created_at" => null
          "updated_at" => null
        ]
        #changes: []
        #casts: []
        #dates: []
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #guarded: array:1 [
          0 => "*"
        ]
      }
      3 => Task {#296
        #fillable: array:4 [
          0 => "name"
          1 => "description"
          2 => "start_date"
          3 => "end_date"
        ]
        #table: "tasks"
        #connection: "sqlite"
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:7 [
          "id" => "4"
          "name" => "TEST"
          "description" => "TEST"
          "start_date" => "2019-11-08 00:00:00"
          "end_date" => "2019-11-09 00:00:00"
          "created_at" => null
          "updated_at" => null
        ]
        #original: array:7 [
          "id" => "4"
          "name" => "TEST"
          "description" => "TEST"
          "start_date" => "2019-11-08 00:00:00"
          "end_date" => "2019-11-09 00:00:00"
          "created_at" => null
          "updated_at" => null
        ]
        #changes: []
        #casts: []
        #dates: []
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #guarded: array:1 [
          0 => "*"
        ]
      }
    ]
  }
  +exception: null
}