Show events in fullcalendar through JSON

1

I'm just learning to use the bootstrap fullCalendar and after searching for the solution I could not find it, my code is as follows:

script

$(document).ready(function() {

    $('#calendar').fullCalendar({
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,basicDay'
      },
      defaultDate: new Date(),
      navLinks: true, 
      editable: true,
      eventLimit: true, 
      events: {
        url: 'getEventos/',
        error: function() {
          alert(1);
        }
      }
    });
  });  

driver

public function getEventos(){
    $eventos = Eventooooo::find(1);
    $evento = ['title' => $eventos->evento,
               'start' => $eventos->fechaEvento,
               'end'   => $eventos->fechaEvento,
    ];
    return response()->json($evento);
}

I'm sending a JSON with the indexes in the way I expect to receive it calendar so I just send the response to 'event', and indeed, as a response it is bringing me the data I need. With this code that I am using, it does not show me any errors but it does not show me the event in the calendar, I was following a tutorial where the person did not show the data so he had to do the following:

tutorial code

 $(document).ready(function() {

  $.get('getEventos/', function(response, state){
    $('#calendar').fullCalendar({
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,basicDay'
      },
      defaultDate: new Date(),
      navLinks: true, // can click day/week names to navigate views
      editable: true,
      eventLimit: true, // allow "more" link when too many events
      events: $.parseJSON(response),
    });
  });     

});

But that generates an error for me and it did not work for me. I would like to know if someone has had this same problem and how to solve it, thanks.

    
asked by Jorge Fernandez 10.05.2017 в 07:12
source

1 answer

1

You could try using something like the following examples, since it could be something related to the expected dataType

$.get('getEventos/', function(response, state){
    // lógica
}, 'json');  

or also with:

$.getJSON('getEventos/', function(response, state){
    // lógica
});
    
answered by 11.05.2017 в 08:17