GeekMom
GeekMom

Reputation: 11

FullCalendar not displaying JSON Events

I have looked at all the examples and I can't figure out why FullCalendar won't show my events. The calendar shows up and if I put the json directly in the events: it works so the json seems correct. Please help! -- Thanks

Javascript

$(document).ready(function() {
    $('#calendar').fullCalendar({
        header :{
            left: 'prev, next, today',
            center: 'title',
            right: 'month, agendaWeek, agendaDay',
            ignoreTimezone: false
        },
        selectable: true,
        selectHelper: true,
        editable: true,
//      events: [{"id":"1","title":"Test","start":"2012-01-20T13:00:00-08:00","end":"2012-01-20T14:00:00-08:00","allDay":false}] WORKS
        events:'getJSONEvents.php',     
        loading: function(bool) { 
            if (bool) $('#loading').show(); 
            else $('#loading').hide(); 
         } 
    });
})

PHP

<?php
    $query = "SELECT * FROM `Events` ORDER BY `id` DESC";
        if( GLOBALTESTMODE && $testMode){
            $rows = mysql_query($query, $myconnection) or trigger_error("Error: Query failed.".$query, E_USER_ERROR);           
        } else {
            $rows = mysql_query($query, $myconnection) or trigger_error("Error: Query failed.", E_USER_ERROR);          
        }


        //write object to array
        $eventsArray = array();
        $events = array();
        date_default_timezone_set('America/Los_Angeles'); 
        while($row = mysql_fetch_array($rows, MYSQL_ASSOC)) {       
            $start = $row['start'];
            $end = $row['end'];
            $eventsArray['id'] =  $row['id'];
            $eventsArray['title'] = $row['title'];
            $eventsArray['start'] = date('c', strtotime($start));
            $eventsArray['end'] = date('c', strtotime($end));
            if ($row['allDay'] == "true") {
                $eventsArray['allDay'] = true;
            } else {
                $eventsArray['allDay'] = false;
            }
            $events[] = $eventsArray;
        }
    }

    header('Content-type: application/json');   
    echo json_encode($events);
?>

Upvotes: 1

Views: 2353

Answers (2)

benjieb
benjieb

Reputation: 85

try to check if your date values are either: a. IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST") b. a string in ISO8601 format (ex: "2009-11-05T13:15:30Z") c. UNIX timestamp

I have encountered this kind of problem wherein my date - "2012-04-7T12:16:30Z" was not accepted. Upon adding a '0' to the day value - "2012-04-07T12:16:30Z", I started receiving JSON events.

A gotcha moment!

Hope this helps!

Upvotes: 0

Matt Healy
Matt Healy

Reputation: 18521

Have you verified that the PHP script returns the expected results?

Also make sure that the PHP script is actually being called correctly by the Javascript (you could check this in your web server access logs). If it is not being called correctly, maybe you need to specify the full path to the PHP file.

Upvotes: 0

Related Questions