我是javascript和json的新手。我试图将存储在我的数据库中的事件显示到日历中。但它没有显示出来。
这是我的json-events.php
<?php
include("connect.php");
$year = date('Y');
$month = date('m');
$command = "SELECT * FROM planner";
$result = mysql_query($command) or die (mysql_error());
$bookings = array();
while ($row = mysql_fetch_array($result)) {
echo "hi";
$start = date("Y-m-d", strtotime($row['from_time']));
$end = date("Y-m-d", strtotime($row['to_time']));
$id = $row['plan_id'];
//$eventsArray['plan_id'] = (int)trim($myid);
//$eventsArray['title'] = $row['title'];
$title = $row['purpose'];
//$title = $row['title'];
//echo $title;
//$eventsArray['company'] = $title;
//$eventsArray['from_time'] = $start;
//$eventsArray['to_time'] = $start;
$url = "edit_calendar.php?calendarid=".$row['plan_id'];
// $eventsArray['end'] = $end;
// $eventsArray['allDay'] = false;
// $events[] = $eventsArray;
$bookings = array(
'id' => $id,
'title' => $title,
'start' => $start,
'end' => $end,
'url' => $url
);
echo json_encode($bookings);}
?>
在这里我将其连接到calendar.js
jsonEvents: function() {
if($('#calendar_json').length) {
$('#calendar_json').fullCalendar({
header: {
left: 'month,agendaWeek,agendaDay',
center: 'title',
right: 'prev,next'
},
buttonText: {
prev: '<i class="icon-chevron-left icon-white cal_prev" />',
next: '<i class="icon-chevron-right icon-white cal_next" />'
},
editable: true,
firstDay: 1, // 0 - Sunday, 1 - Monday
events: "json-events.php",
eventDrop: function(event, delta) {
alert(event.title + ' was moved ' + delta + ' days\n' +
'(should probably update your database)');
}
});
}
和我的dashboard.php页面
<div class="w-box w-box-green">
<div class="w-box-header"></div>
<div class="w-box-content">
<div id='calendar_json'></div>
</div>
<div class="w-box-footer">
<p class="f-text">JSON events fetched from a script</p>
</div>
</div>
但它只显示日历而非数据库中的数据。
有人可以建议吗
当我回应json事件时,我得到了正确的输出
{"id":"3","title":"sdfsfsd dsdsbfb","start":"2015-01-05","end":"2015-01-14","url":"edit_calendar.php?calendarid=3"}
但是在日历中没有显示任何内容