Reputation: 2994
I'm using JQuery FullCalendar version 1.5.4 and I want to set the events with JQuery.
I use $.getJSON to call a php file, that retreive my data in my MySQL database.
When I limit my query with limit 0,1 , everything works fine. The event is sucessfully displayed in the calendar. However, when my php return an array of object, I get the error : Uncaught TypeError: Cannot call method 'replace' of null
the JSON data returned by my PHP Page looks like this :
[{"id":1,"title":"Halloween ","start":"2013-02-08 00:00:00","end":"2013-02-08 00:00:00","allDay":true},{"id":2,"title":null,"start":"2013-02-12 00:00:00","end":"2013-02-12 00:00:00","allDay":true},{"id":3,"title":"Sortie Valcartier","start":"2013-02-20 00:00:00","end":"2013-02-20 00:00:00","allDay":true}]
The PHP code looks like this :
<?php
//header('content-type: application/json; charset=utf-8');
mysql_connect("localhost","root") or die (" NOPE . [" . mysql_error() . "]");
mysql_select_db("garderie");
$query = "select a.ActiviteID as ActiviteID,a.nom as Nom , cd.datedujour as Jour from activites a
inner join calendrieractivite ca
on a.activiteid = ca.activiteid
inner join calendrierdate cd
on ca.dateid = cd.dateid
";
$result = mysql_query($query);
$events = array();
$i = 0;
$year = date('Y');
$month = date('m');
while($ligne = mysql_fetch_array($result))
{
$id = $ligne["ActiviteID"];
$nom = $ligne["Nom"];
$e = array(
'id' => (int)$id,
'title' => $nom,
'start' => $ligne["Jour"],//$start,
'end' => $ligne["Jour"],
'allDay' => true
);
$events[$i] = $e;
$i++;
}
mysql_close();
echo (json_encode($events));
?>
the jquery code looks like this
...
$.getJSON('json_events.php', null, function(data){
$('#calendar').fullCalendar({
events: data,
...
Upvotes: 0
Views: 3306
Reputation: 17608
You'll need to filter your events on the php side, and make sure every event has a title. When you pass a null title to FullCalendar, it seems to break the script.
{"id":2,"title":null,"start":"2013-02-12 00:00:00","end":"2013-02-12 00:00:00","allDay":true}
Upvotes: 2