FullCalendar: chmar an external file Json

3

Good afternoon, I'm trying to load an event into FullCalendar. The problem is as follows

$(document).ready(function() {
    $('#calendar').fullCalendar({
        header: {
                left: 'today',
                center: 'prev, title, next',
                right: 'month,basicWeek,basicDay'
            },
                        eventClick:  function(event) {
                             $('#modalTitle').html(event.title);
                             $('#modalBody').html(event.description);
                             $('#eventUrl').attr('href',event.url);
                             $('#fullCalModal').modal();
                             return false;
                        },
            navLinks: true, // can click day/week names to navigate views
            editable: true,
            eventLimit: true, // allow "more" link when too many events
                events:[
                    <?php include('process.php') ?>
               ]
      });
});

Process.PHP

<?php
    $title = "Jose";
    $start = "2016-11-01";

echo "{
       title: '$title' ,
       start: '$start' 
       }";
?>

This way I can load, but would like to know how I do calling a JSON? I tried in a number of ways ($ .getJson, $ .get, Json.parser (), etc ...) Does anyone have any tips?

    
asked by anonymous 01.11.2016 / 19:21

2 answers

0

I use fullcalendar's own events, follow the code:

events: function(start, end, timezone, callback) {

   //chama o ajax e retorna um  result/promise com os dados 'data'
   	var events = []; //create array to events
		$.each(data, function(index, val) { //passa por cada resultado do array
			events.push({							//adiciona os dados no array 'events'
				title: val.title,
				start: val.start,
			})
		});
		callback(events); //callback que irá preencher o calendário, com o array de eventos.
	}
},

It will load all events returned from ajax, in the calendar, any questions, just contact.

    
01.11.2016 / 19:55
1

You can use ajax to fetch this JSON and when ajax completes run the code you have. Something like this:

$(document).ready(function() {
    $.getJSON("/Process.PHP", function(event) {
        $('#calendar').fullCalendar({
            header: {
                left: 'today',
                center: 'prev, title, next',
                right: 'month,basicWeek,basicDay'
            },
            eventClick: function(event) {
                $('#modalTitle').html(event.title);
                $('#modalBody').html(event.description);
                $('#eventUrl').attr('href', event.url);
                $('#fullCalModal').modal();
                return false;
            },
            navLinks: true, // can click day/week names to navigate views
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events: [event]
        });
    });
});

You will eventually want to pass an array, not just one object at a time. In this case in JavaScript you can have events: events and in PHP make echo of an array. Remember that you can use the% % of PHP to generate JSON.

    
01.11.2016 / 19:26