Похож на хорошо известную проблему, но я все еще не мог найти решение.Fullcalendar Json Events Feed Not Displaying Anything
Я тестирую Fullcalendar с Планировщиком на своем локальном хосте. Я пытаюсь заменить статический поток данных как массив данными из базы данных MySQL. Я следил за рекомендациями, но события не отображаются.
Вот мой код:
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
header: {
left: 'prev,next',
center: 'title',
right: 'today'
},
views: {
agendaWeekly: {
type: 'agenda',
duration: { days: 7 },
// views that are more than a day will NOT do this behavior by default
// so, we need to explicitly enable it
groupByResource: true,
//// uncomment this line to group by day FIRST with resources underneath
groupByDateAndResource: true
}
},
defaultView: 'agendaWeekly',
lang: 'sl',
businessHours: {
start: '08:00', // a start time (10am in this example)
end: '22:00', // an end time (6pm in this example)
},
allDaySlot: false,
minTime: '08:00:00',
maxTime: '22:00:00',
defaultDate: '2016-03-30',
nowIndicator: true,
resourceLabelText: 'Igrisca',
resources: [
{ id: '1', title: 'Igrišče 1', eventColor: 'green' },
{ id: '2', title: 'Igrišče 2', eventColor: 'green' }
],
selectable: true,
selectHelper: true,
selectOverlap: false,
select: function(start, end, resource) {
var title = prompt('Rezervacija termina za (ime, tel):');
var eventData;
if (title) {
eventData = {
title: title,
start: start,
end: end,
resourceId: resourceId
};asas
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
}
$('#calendar').fullCalendar('unselect');
},
editable: true,
eventLimit: true, // allow "more" link when too many events
events: 'myfeed.php',
});
});
</script>
Последняя строка кода вызывает внешний файл myfeed.php, который имеет следующий код:
$dblink = mysql_connect('localhost', 'un', 'pw') or die(mysql_error());
mysql_select_db('db');
$rs = mysql_query($sql, $dblink);
$event_array = array();
if ($rs && mysql_num_rows($rs)) {
while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
$event_array[] = array(
'id' => $row['BookingID'],
'title' => $row['BookingNote'],
'start' => $row['BookingStartTime'],
'end' => $row['BookingEndTime'],
'resourceId' => $row['CourtID']
);
}}
echo json_encode($event_array);
Результат JSON является следующий массив:
[{"id":"1","title":"Goran 041\/853-184","start":"2016-03-30T19:00:00","end":"2016-03-30T21:00:00","resourceId":"1"},{"id":"2","title":"Janez","start":"2016-03-31T10:00:00","end":"2016-03-31T12:00:00","resourceId":"2"},{"id":"3","title":"Sa\u0161o","start":"2016-03-31T14:00:00","end":"2016-03-31T16:00:00","resourceId":"2"}]
Если я вручную добавлю этот массив, он будет работать, и события будут показаны в календаре. Но я не могу заставить его работать через JSON. В чем может быть проблема?
Действительно ли ваш «myfeed.php» называется или нет? – cverb
ДА это так. Вот ссылка, я только что загрузил файлы на рабочий сервер: http://www.slotenis.si/rezervacije/ – gdolenc
попробуйте установить заголовок заголовка json ('Content-Type: application/json'); 'перед вашим эхом – Yuri