无法使用json事件提供完整日历

时间:2012-11-24 01:53:17

标签: php jquery json fullcalendar

我正在尝试以下代码.. 整合fullcalendar: -

<doctype! html>
    <html lang="urf-8">
    <head>
    <title>Full calendar</title>
    <link rel="stylesheet" href="fullcalendar.css"/>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css"/>
    <script type='text/javascript' src='jquery.js'></script>
    <script type='text/javascript' src='fullcalendar.js'></script>
    <script>
    $(document).ready(function() {
        $('#cal').fullCalendar({
            // put your options and callbacks here
            theme: true,
            header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,basicWeek,basicDay,agendaWeek,agendaDay'
                    },
            editable: false,
            events: "json-events.php",
    })
    });

    </script>
    </head>
    <body>
        <div id="cal" ></div>
    </body>
    </html>

Json-events.php代码: -

<?php
    include("connect.php");
    $query = "select * from calendar";

    $res = mysql_query($query) or die(mysql_error());
    $events = array();
    while ($row = mysql_fetch_assoc($res)) {
        $eventsArray['id'] =  $row['calendar_id'];
        $eventsArray['title'] = $row['subject'];
        $eventsArray['start'] = mktime($row['start_date_time']);
        $events[] = $eventsArray;
    }
    echo json_encode($events);
    ?>

为了调试我访问json-events.php时我得到了结果,但是在fullcalendar中没有显示任何事件。

请帮帮我..

1 个答案:

答案 0 :(得分:4)

问题在于JSON中日期字符串的格式。格式与插件的日期格式不兼容。如果在php中使用strtotime()转换为UNIX时间戳,它们将起作用。