Wednesday, August 8, 2012

How to import json array into jQuery calendar

Hi
I'm trying to feed a jQuery calendar with data from Silverstripe. I've installed the perfectly well-working Calendar Event module, but all I want now is to pull out some Calendar Events and return them as a json array. Here is the code for initiating the calendar:
$(document).ready(function() {
   
      $('#calendar').fullCalendar({
         draggable: true,
         events: "json_events.php",
         eventDrop: function(event, delta) {
            alert(event.title + ' was moved ' + delta + ' days\n' +
               '(should probably update your database)');
         },
         loading: function(bool) {
            if (bool) $('#loading').show();
            else $('#loading').hide();
         }
      });
      
   });
And here is the json_events.php:
   $year = date('Y');
   $month = date('m');
   echo json_encode(array(
   
      array(
         'id' => 1,
         'title' => "Event1",
         'start' => "$year-$month-10",
         'url' => "http://yahoo.com/"
      ),
      
      array(
         'id' => 2,
         'title' => "Event2",
         'start' => "$year-$month-20",
         'end' => "$year-$month-22",
         'url' => "http://yahoo.com/"
      )
   
   ));
?>

No comments:

Post a Comment