Fullcalendar - 未捕获错误:语法错误,无法识别的表达式:JSON输出

时间:2014-10-21 08:29:44

标签: php jquery ajax json fullcalendar

我无法从我的JSON中获取事件以在FullCalendar中呈现,但我知道AJAX / JSON正在运行,因为它在Chrome调试器的“网络”选项卡中显示。

我有以下JS并且我一直收到以下错误(见下文)。我无法找到导致它的原因(" sizzle"错误)。

Chrome调试器出错:

Uncaught Error: Syntax error, unrecognized expression: [{"id":"000000000000001","title":"Test","start":"2014-10-19 16:30:00","end":"2014-10-19 17:00:00","url":"","allDay":"false"},{"id":"000000000000002","title":"James","start":"2014-10-23 09:00:00","end":"2014-10-23 17:00:00","url":"","allDay":"true"}]

从jquery-1.11.1.js抛出的细节:

Sizzle.error = function( msg ) {
    throw new Error( "Syntax error, unrecognized expression: " + msg );

JQuery - Fullcalendar:

$(document).ready(function() {
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var calendar = $('#calendar').fullCalendar({
        allDayDefault: false,
        editable: true,
        defaultView: 'agendaWeek',
        header: {
            left: 'prev,next prevYear,nextYear today',
            center: 'title',
            right: 'agendaDay,agendaWeek,month',
        },

        events: function(start, end, timezone, callback) {
            JSON.parse($.ajax({
                type: "GET",
                url: "required/events.php",
                async: false,
                success: function(doc) {
                    var events = [];
                    $(doc).find('event').each(function() {
                        events.push({
                        id: $(this).attr('id'),
                        title: $(this).attr('title'),
                        start: $(this).attr('start'),
                        end: $(this).attr('end'),
                        allDay: $(this).attr('allDay')
                });
            });
            callback(events).show();
        }
            }).responseText);
        }, 

        // Convert the allDay from string to boolean
        eventRender: function(event, element, view) {
            if (event.allDay === 'true') {
                event.allDay = true;
            } else {
                event.allDay = false;
            }
        },
        selectable: true,
        selectHelper: true,
        select: function(start, end, allDay) {
            var title = prompt('Event Title:');
            //var url = prompt('Type Event url, if exits:');
            if (title) {
                var start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
                var end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
                JSON.parse(
                    $.ajax({
                        url: 'actions/event_add.php',
                        data: 'title=' + title + '&start=' + start + '&end=' + end,
                        type: "POST",
                        success: function(json) {
                            alert('Added Successfully');
                        }
                    })
                    );
                calendar.fullCalendar('renderEvent', {
                        title: title,
                        start: start,
                        end: end,
                        allDay: allDay
                    },
                    true // make the event "stick"
                );
            }
            calendar.fullCalendar('unselect');
        },

        editable: true,
        eventDrop: function(event, delta) {
            var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
            var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
            $.ajax({
                url: 'actions/event_update.php',
                data: 'title=' + event.title + '&start=' + start + '&end=' + end + '&id=' + event.id,
                type: "POST",
                success: function(json) {
                    alert("Updated Successfully");
                }
            });
        },

        eventClick: function(calEvent, jsEvent, view) {

            alert('Event: ' + calEvent.title + ' Start: ' + calEvent.start + ' Finish: ' + calEvent.end + ' allDay: ' + calEvent.allDay);
        },

        eventResize: function(event) {
            var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
            var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
            $.ajax({
                url: 'actions/event_update.php',
                data: 'title=' + event.title + '&start=' + start + '&end=' + end + '&id=' + event.id,
                type: "POST",
                success: function(json) {
                    alert("Updated Successfully");
                }
            });

        }

    });

});

0 个答案:

没有答案