Richard Delay
Richard Delay

Reputation: 65

FullCalendar clientEvents sending to Laravel Controller

I am trying to post my FullCalendar list of events to a PHP controller. The ajax sending and the receiving are correctly working as when I put console.log for events, it shows the events correctly.

No here is my events array : var events = $('#calendar').fullCalendar( 'clientEvents');

Which is sent through this event $("#save").click(function (e)

The Problem : Whatever I put in the controller to debug or to read the Input::all data or a specific Input->get('events') which is sent from ajax, I get the error in the console :

`too much recursion with about a hundred of n.fn.extend() below it.

Ajax :

$("#save").click(function (e) {
            e.preventDefault();
            var events = $('#calendar').fullCalendar( 'clientEvents');

            $.ajax({
                url: "/admin/m/submit",
                headers: {
                    'X-CSRF-TOKEN': $('#crsf').val()
                },
                type: "GET",
                contentType: "application/json",
                data: {events:events},
                dataType: "json",
                success: function(response){
                    if (response['state']===0)

                        toastr.error('erreor');
                },
                error : function(e){
                    console.log(e.responseText);
                }

            });
        });

Controller :

$d= Input::all();
        dd($d['events']);
        return response()->json(['state'=>0],200);

dd is the debugger for laravel which as this is an ajax request will show it's result in console.

Upvotes: 1

Views: 940

Answers (1)

Chaibi Alaa
Chaibi Alaa

Reputation: 1386

The events array of OBJECTS you are sending is too recursive if you simply open any browser debugger you'll see it contains really unused staff. Your code has nothing to do with the error, but sending the events like it does.

For that, my solution is to create another array grabbing only needed staff :

    var events = $('#calendar').fullCalendar( 'clientEvents');
                var fE = [];
                $.each( events, function( key, value ) {
                    fE.push({
                        id : value._id,
                        Item : [{
 title : value.title,
                            start : value.start._d,
                            end : value.end._d}]
                    });
                });
                console.log(fE);

I tried this, send the array after this, it will be as clean as possible.

Upvotes: 1

Related Questions