我正在使用 JQuery FullCalendar 1.5.4 版,我想用 JQuery 设置事件。
我使用 $.getJSON 来调用一个 php 文件,该文件在我的 MySQL 数据库中检索我的数据。
当我用 limit 0,1 限制我的查询时,一切正常。该事件已成功显示在日历中。但是,当我的 php 返回一个对象数组时,我得到了错误:Uncaught TypeError: Cannot call method 'replace' of null
我的 PHP 页面返回的 JSON 数据如下所示:
[{"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}]
PHP 代码如下所示:
<?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));
?>
jquery 代码看起来像这样
...
$.getJSON('json_events.php', null, function(data){
$('#calendar').fullCalendar({
events: data,
...