Fullcalendar 无法解析本地 JSON
Fullcalendar not being able to parse local JSON
我有一个控制器,它从数据库中获取我需要的信息,我将它构造成一个数组,然后用 json_encode[=32= 构造成一个 JSON ].
但是,我在浏览器中得到的错误是这样的:
Error from the Chrome console
这张图片是来自我的控制器的 JSON
My JSON from the controller
控制器
<?php
require_once '../classes/functions.php';
$newEvent = new calendario();
$events = $newEvent->getEvents();
$newEvent = null;
foreach ($events as $event) {
$data[] = array(
'title' => $event['titulo'],
'start' => $event['inicio'],
'end' => $event['fin'],
);
header('Content-Type: application/json');
}
print_r(json_encode($data));
我页面上的完整日历代码
var calendarEl = document.getElementById('calendar');
if (calendarEl) {
document.addEventListener('DOMContentLoaded', function() {
var calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'ca',
plugins: ['dayGrid', 'timeGrid', 'list', 'bootstrap'],
timeZone: 'UTC',
themeSystem: 'bootstrap',
header: {
left: 'today, prev, next',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
},
buttonIcons: {
prev: 'fe-arrow-left',
next: 'fe-arrow-right',
prevYear: 'left-double-arrow',
nextYear: 'right-double-arrow'
},
weekNumbers: true,
events: {
url: '../controllers/getEvents.php',
type: 'GET',
format: 'json',
failure: function() {
alert('Hem trobat errors quan hem intentat exportar les visites de la base de dades!');
},
},
// events: 'https://fullcalendar.io/demo-events.json',
// events: '../controllers/getEvents.php',
});
calendar.render();
});
}
为了尝试,您会看到我尝试将演示 fullcalendar 用于他们的示例中,这完美无缺,但我的 JSON 没有...
所以,问题出在 functions.php。正如 @ADyson 评论的那样,那里有一个元标记,并且 require_once 我每次都在打印它。
感谢所有评论和帮助我的人,再次感谢@ADyson.
我有一个控制器,它从数据库中获取我需要的信息,我将它构造成一个数组,然后用 json_encode[=32= 构造成一个 JSON ].
但是,我在浏览器中得到的错误是这样的: Error from the Chrome console
这张图片是来自我的控制器的 JSON My JSON from the controller
控制器
<?php
require_once '../classes/functions.php';
$newEvent = new calendario();
$events = $newEvent->getEvents();
$newEvent = null;
foreach ($events as $event) {
$data[] = array(
'title' => $event['titulo'],
'start' => $event['inicio'],
'end' => $event['fin'],
);
header('Content-Type: application/json');
}
print_r(json_encode($data));
我页面上的完整日历代码
var calendarEl = document.getElementById('calendar');
if (calendarEl) {
document.addEventListener('DOMContentLoaded', function() {
var calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'ca',
plugins: ['dayGrid', 'timeGrid', 'list', 'bootstrap'],
timeZone: 'UTC',
themeSystem: 'bootstrap',
header: {
left: 'today, prev, next',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
},
buttonIcons: {
prev: 'fe-arrow-left',
next: 'fe-arrow-right',
prevYear: 'left-double-arrow',
nextYear: 'right-double-arrow'
},
weekNumbers: true,
events: {
url: '../controllers/getEvents.php',
type: 'GET',
format: 'json',
failure: function() {
alert('Hem trobat errors quan hem intentat exportar les visites de la base de dades!');
},
},
// events: 'https://fullcalendar.io/demo-events.json',
// events: '../controllers/getEvents.php',
});
calendar.render();
});
}
为了尝试,您会看到我尝试将演示 fullcalendar 用于他们的示例中,这完美无缺,但我的 JSON 没有...
所以,问题出在 functions.php。正如 @ADyson 评论的那样,那里有一个元标记,并且 require_once 我每次都在打印它。
感谢所有评论和帮助我的人,再次感谢@ADyson.