我试图通过ajax发送事件数据以将其保存到数据库。下面是我的代码:

select: function(start, end) {
            var title = prompt('Event Title:');
            if (title) {
                calendar.fullCalendar('renderEvent',
                    {
                        title: title,
                        start: start,
                        end: end
                    },
                    true // make the event "stick"
                );
            }
            $.ajax({
                url: '/event/new',
                data: {'title': title, 'start': start, 'end':end},
                type: "POST",
                success: function (json) {
                    alert('Added Successfully');
                }
            });
            calendar.fullCalendar('unselect');
        },


根据选定的时间,添加事件可以正常进行。但是我收到以下错误:
javascript - 全日历通过ajax传递事件数据产生错误-LMLPHP

如果单击该错误,则会将我带到moment.js到以下行:

function locale_calendar__calendar (key, mom, now) {
        var output = this._calendar[key];
        return isFunction(output) ? output.call(mom, now) : output;
    }


如果删除代码的ajax部分,则没有错误!但是当然,我需要将事件保存到数据库。
任何想法,我在做什么错?

最佳答案

我通过将开始和结束转换为JSON数据解决了这个问题。当前如下所示:

     $.ajax({
                url: '/event/new',
                data: {'title': title, 'start': start.toJSON(), 'end':end.toJSON()},
                type: "POST",
                success: function (json) {
                    alert('Added Successfully');
                }
            });

07-24 09:47
查看更多