【发布时间】:2016-09-25 16:02:39
【问题描述】:
我正在按日历工作。现在我需要通过 ajax 调用显示数据库中的所有事件。到目前为止,我已经通过 JSON 从数据库中获取事件。
我的JSON输出在var_dump之后如下:
array (size=3)
0 =>
array (size=7)
'title' => string 'hi' (length=2)
'id' => int 1
'start' => string '2016-05-30 00:00:00.000' (length=23)
'rendering' => string 'background' (length=10)
'backgroundColor' => string '#ff9999' (length=7)
'className' => string 'event-full' (length=10)
'textColor' => string 'white' (length=5)
1 =>
array (size=7)
'title' => string 'vibrator' (length=8)
'id' => int 3
'start' => string '2016-05-26 00:00:00.000' (length=23)
'rendering' => string 'background' (length=10)
'backgroundColor' => string '#ff9999' (length=7)
'className' => string 'event-full' (length=10)
'textColor' => string 'white' (length=5)
2 =>
array (size=7)
'title' => string 'vibrator' (length=8)
'id' => int 8
'start' => string '2016-05-26 00:00:00.000' (length=23)
'rendering' => string 'background' (length=10)
'backgroundColor' => string '#ff9999' (length=7)
'className' => string 'event-full' (length=10)
'textColor' => string 'white' (length=5)
我的ajax脚本如下:-
events: function(start, end, timezone, callback)
{
$.ajax({
url: "calendar/show_events",
type: 'POST', // Send post data
data: 'type=fetch_events',
async: true,
success: function(s){
dynamic_events =s;
alert(dynamic_events);
// $('#calendar').fullCalendar('addEventSource', JSON.parse(dynamic_events));
var dynamic_events = [];
$(doc).find('event').each(function() {
events.push({
title: $(this).attr('title'),
start: $(this).attr('start') // will be parsed
});
});
callback(events);
}
});
}
我的代码有什么错误。?我现在想学。
任何人都可以帮助我并拯救我的一天吗?
我需要在FullCalendar 中显示所有事件。
【问题讨论】:
-
你得到什么错误?
-
@Eyal Abir, Uncaught ReferenceError: doc is not defined
-
直到我的警报(动态事件);我收到了回复,但我不知道如何在 fullcalendar 中制作事件
-
您误用了成功函数中的变量。 doc 确实没有定义。您可能打算检查
s变量。 -
好的,如果是这样,我应该如何检查's'变量。不知何故,我想以这种方式显示完整日历中的事件..
标签: javascript jquery ajax fullcalendar jquery-events