我正在努力将 MySQL 事件集成到 Fullcalendar 中。
我读过很多指南/帖子,但我无法从 json 脚本导入事件。 现在,如果我将“myfeed.php”的 JSON 结果粘贴到 fullcalendar 中,我的日历就会正常工作并且包含所有事件。如果我将 fullcalendar 链接到 myfeed.php,则日历为空。我还尝试将我的日历链接到 fullcalendar 的“get-events.php”(应该与 myfeed.php 一起使用),但日历始终为空。 :/
这是我的完整日历:
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
eventLimit: true, // allow "more" link when too many events
events: {
url: 'fullcalendar/php/get-events.php',
//url: 'fullcalendar/myfeed.php',
error: function() {
$('#script-warning').show();
}
},
loading: function(bool) {
$('#loading').toggle(bool);
}
});
});
这是 myfeed.php 的结果:
[{“id”:”1″,”title”:”allenamentosimone”,”allDay”:”false”,”start”:”1423036800″,”end”:”1423044000″,”url”:”pippo”},
{“id”:”2″,”title”:”allenamentodue”,”allDay”:”true”,”start”:”1423310400″,”end”:”1423335600″,”url”:”pluto”}]
和myfeed.php是visible on pastebin (对于站点 jsonformatter,结果是有效的 json,但文件不是有效的 json)。
有什么建议吗?
<小时/>更新:
我已将事件网址更改为:
url:'fullcalendar/myfeed.php'
此外,我还更改了 json 的日期格式 YYYY-MM-DD HH:II:SS,现在我可以在全日历上查看我的事件。但是我在全天模式下看到所有事件:/
这是新的 json 返回:
[
{"id":"1","title":"allenamentosimone","allDay":"false","start":"2015-02-04 09:00:00","end":"2015-02-04 11:00:00","url":"pippo"},
{"id":"2","title":"allenamentodue","allDay":"true","start":"2015-02-07 13:00:00","end":"2015-02-07 20:00:00","url":"pluto"}
]
<小时/>
更新 N.2:
如果我不在 allDay 部分写任何内容,我的全日历就可以完美运行!这是最后一个json返回:
[
{"id":"1","title":"allenamentosimone","allDay":"","start":"2015-02-04 09:00:00","end":"2015-02-04 11:00:00","url":"pippo"},
{"id":"2","title":"allenamentodue","allDay":"true","start":"2015-02-07 13:00:00","end":"2015-02-07 20:00:00","url":"pluto"}
]
最佳答案
events
应该是从数据库提供的单个 URL。
所以替换这样的事件:
events: 'fullcalendar/php/get-events.php',
检查浏览器检查器是否尝试访问数据库文件。在 Chrome 中,使用 Ctrl+Shift+i 打开它并导航到网络
选项卡。数据库 URL 与您使用它的浏览器 URL 相关。
例如,如果您有页面 testfullcalnedar.io/mycalendar
假设您的 php 位于 testfullcalnedar.io/mycalendar/fullcalendar/php/get-events.php'
。
然后在脚本事件提要 URL 将为 fullcalendar/php/get-events.php
或 /mycalendar/fullcalendar/php/get-events.php
说明 - 如果您以 /
开始提要 URL,它将从您的域的根开始搜索,否则它将相对于脚本所在的位置进行搜索。在我的示例案例中,脚本在 testfullcalnedar.io/mycalendar
关于php - MySQL、JSON 和 Fullcalendar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28629563/