[英]fullcalendar.js is not reading the php json feed
我想通过php json feed预填充我的fullcalendar实例。
页面加载正常(没有404之类的东西),但日历未显示任何事件。
生成json:
<?php
require("../config/config.php");
$uid = $_SESSION['uid'];
$res = $db->query("SELECT * FROM slots WHERE tid = '$uid'");
$data = array();
while($row = $res->fetch_assoc())
{
$event = array();
$event['editable'] = false;
$event['id'] = "fixE_".$row['id'];
$event['title'] = getSlotStatus($row['status']);
$event['sid'] = $row['sid'];
$event['status'] = $row['status'];
$event['start'] = $row['start'];
$event['end'] = $row['end'];
$event['standby'] = $row['standby'];
if(strpos($data['status'],"_old"))
{
$event['textColor'] = '#000000';
$event['color'] = '#cccccc';
$event['className'] = 'lessonSlotOld';
}
else
{
$event['color'] = getColorCode($row['status']);
if($row['standby'])
{
$event['borderColor'] = '#0000FF';
}
}
$data[] = $event;
}
echo json_encode(array("events"=>$data));?>
这是我在其中插入供稿的全日历代码的一部分:
events:
{
url: 'include/fetchSlots.php',
type: 'POST',
error: function(){alert("There was an error fetching events")}
},
php的json输出如下所示(这只是一部分,因为整个响应会太多;))
{"events":[{"editable":false,"id":"fixE_164","title":"Slot is closed","sid":"0","status":"closed","start":"2015-06-06T04:00:00+08:00","end":"2015-06-06T04:30:00+08:00","standby":"0","color":"#B20000"}]}
好的,这是解决方案/错误。
fullcalendar唯一的问题是实际json的发布行:
echo json_encode(array("events"=>$data));
fullcalendar不需要“事件”,也不需要两次包装的数组。 因此,解决方案就是直接输出数据数组:
echo json_encode($data);
然后,所有事件均正确加载。
啊,对于所有守望者来说,是的,我发现了错误的命名变量;)
if(strpos($data['status'],"_old"))
至
if(strpos($row['status'],"_old"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.