php - MySQL、JSON 和 Fullcalendar

标签 php jquery mysql json fullcalendar

我正在努力将 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.phpvisible 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/

相关文章:

php - 获取连接表的列名

php - 我如何在 CakePHP 中使用缓存?

javascript - 如何相交两个数组并保留 key

php - isset() 和 array_key_exists() 有什么区别?

javascript - Amcharts 仅显示有关调整大小事件的数据

javascript - <a target ="_blank"> onclick 应该打开一个新选项卡,但焦点应该在当前选项卡上,而不是在新选项卡上,并且应该适用于 chrome 和 mozilla

javascript - jQuery 应用事件处理程序的最佳方式

php - 以 HTML 形式返回 PHP/MySQL 结果以供编辑

vhost 的 Php 版本,apache2

php - 计算列中的所有值