FullCalendar fetch data from the php database

2

I'm generating a calendar for a site, and I'm required to use the fullCalendar tool. The question is to get the events by php to my database. In js, the data is listed in the following demo.calendar.js file and contains the following:

;(function( $, window, document, undefined ) {
    $(document).ready(function() {

        // Full Calendar
        if( $.fn.fullCalendar ) {

            var date = new Date();
            var d = date.getDate();
            var m = date.getMonth();
            var y = date.getFullYear();

            $("#mws-calendar").fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                },
                editable: true,
                events: [{
                    title: 'All Day Event',
                    start: new Date(y, m, 1)
                }, {
                    id: 999,
                    title: 'Repeating Event',
                    start: new Date(y, m, d - 3, 16, 0),
                    allDay: false
                }, {
                    title: 'Meeting',
                    start: new Date(y, m, d, 10, 30),
                    allDay: false
                }]
            });
        }
    });

}) (jQuery, window, document);

Now I have a question, is there any way to go get the events by php? Or put this code in a php file? or the header?

I am doing: return the value by jason, but so far without any success.

;(function( $, window, document, undefined ) {

    $(document).ready(function() {

        // Full Calendar
        if( $.fn.fullCalendar ) {

            var date = new Date();
            var d = date.getDate();
            var m = date.getMonth();
            var y = date.getFullYear();

            $("#mws-calendar").fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                },
                editable: true,
                events: './myfeed.php'
            });
        }
    });

}) (jQuery, window, document);

and in the file myfeed.php I have the following (it's an example without the DB query yet, I just needed to see the events below, that the query for is no longer accurate):

<?php

   $year = date('Y'); 
   $month = date('m');

   echo json_encode(array( 

      array( 
         'id' => 1, 
         'title' => "Event1", 
         'start' => "$year-$month-20", 
         'end' => "$year-$month-22", 
         'url' => "http://google.com/" 
      ), 

      array( 
         'id' => 2, 
         'title' => "Event2", 
         'start' => "$year-$month-20", 
         'end' => "$year-$month-22", 
         'url' => "http://yahoo.com/" 
      ) 

   ));

?>
    
asked by anonymous 09.07.2014 / 13:32

1 answer

1

Try to do this:

$.ajax({
type: "POST",
url: "myfeed.php",
data: {       //the data    },
success: function(events)
  {
          $('#mws-calendar').fullCalendar('removeEvents');
          $('#mws-calendar').fullCalendar('addEventSource', events);         
          $('#mws-calendar').fullCalendar('rerenderEvents' );
   }
 });

Also check that the myfeed.php file is in the same folder as the js

    
09.07.2014 / 13:55