Fullcalendar Json事件源不显示任何内容



看起来是一个众所周知的问题,但我仍然找不到解决方案。

我正在本地主机上用Scheduler测试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":"Sau0161o","start":"2016-03-31T14:00:00","end":"2016-03-31T16:00:00","resourceId":"2"}]

如果我手动添加这个数组,它就会工作,并且事件会显示在日历上。但我无法通过JSON使其工作。可能是什么问题?

改为使用事件:

使用

eventSources: getSources()

其中getSources

getSources(){
 var mysources = {
   mysourceone:{
                url: YOUR URL TO GET JSON,
                type: 'POST', 
                data:{
                //SOME DATA YOU MIGHT PASS, NOT important for your problem
                 },
                 cache: false,
                 color: '#C1272D',
                 textColor: 'white'
                 }
              }
  return [mysources.mysourceone];
}

终于开始工作了。问题出现在JSON文件的完整路径中:

一旦我把它从改了

 /wp-content/themes/canvas-child/myfeed.php

 http://www.slotenis.si/wp-content/themes/canvas-child/myfeed.php

我成功了。

相关内容

  • 没有找到相关文章

最新更新