使用MVC和JSON的jquery FullCalendar

我只想尝试做一些非常简单的事情。

我正在使用这里找到的jQuery FullCalendar: http ://fullcalendar.io/

当我将事件数据添加为数组时(如文档示例所提供),日历将填充。 但是,当我尝试通过jQuery执行此操作时,我获得了有效的JSON响应,但事件未填充。

$(document).ready(function () { // page is now ready, initialize the calendar... $('#calendar').fullCalendar({ events: { url: '../calendar/GetCalendarData', type: 'GET', data: {}, success: function (doc) { //alert(doc.title + ' ' + doc.start); var events = []; events.push(doc); alert(events[0].title + ' ' + events[0].start); }, error: function() { alert('there was an error while fetching events!'); }, color: 'yellow', // a non-ajax option textColor: 'black' // a non-ajax option } }); // Code and Documents: http://fullcalendar.io/ }); [HttpPost] public ActionResult PostCalendarData() { return Json(new { title = "Free Pizza", allday = "false", borderColor = "#5173DA", color = "#99ABEA", textColor = "#000000", description = "

This is just a fake description for the Free Pizza.

Nothing to see!

", start = "2015-01-04T22:00:49", end = "2015-01-01", url = "http=//www.mikesmithdev.com/blog/worst-job-titles-in-internet-and-info-tech/" }); } [HttpGet] public ActionResult GetCalendarData() { return Json(new { title = "Free Pizza", allday = "false", borderColor = "#5173DA", color = "#99ABEA", textColor = "#000000", description = "

This is just a fake description for the Free Pizza.

Nothing to see!

", start = "2015-01-04T22:00:49", end = "2015-01-01", url = "http=//www.mikesmithdev.com/blog/worst-job-titles-in-internet-and-info-tech/" }, JsonRequestBehavior.AllowGet); }

我从GetCalendarData调用得到的响应如下:

 {"title":"Free Pizza","allday":"false","borderColor":"#5173DA","color":"#99ABEA","textColor":"#000000","description":"\u003cp\u003eThis is just a fake description for the Free Pizza.\u003c/p\u003e\u003cp\u003eNothing to see!\u003c/p\u003e","start":"2015-01-04T22:00:49","end":"2015-01-01","url":"http=//www.mikesmithdev.com/blog/worst-job-titles-in-internet-and-info-tech/"} 

我已经看到Stack上的其他人有类似的问题,但我没有看到如何在这个日历中使用AJAX和JSON的例子。

我也尝试使用eventSources:documents / example,结果相同。

更新:

我根据我尝试过的不同内容更新了代码。 仍然没有运气。 我看过日期格式。 我已经尝试过系统生成的日期,但我看到的所有内容似乎都指向基于字符串的日期(这是我在更新后的代码中尝试过的)。 不幸的是,这仍然不起作用(至少对我而言)。

仍在寻求帮助。

答案在函数参数中。 放入这些数据后,将在日历中填充数据。

  $(document).ready(function () { var events = []; $('#calendar').fullCalendar({ events: function(start, end, timezone, callback) { $.ajax({ url: source, type: 'POST', data: { }, success: function (doc) { events.push(doc); callback(events); } }); } }); }); 

我不知道这对你来说是否仍然是一个问题,但我确实设法使它适合我。 我几乎有一个确切的案例。 这是我的例子:

 [HttpGet] public JsonResult SerializeEvent(int id) { var sesh = Umbraco.TypedContent(id).Descendants("courseSession"); var eventList = new List(); foreach (var item in sesh) { var eventObj = new EventModel(); eventObj.start = item.GetPropertyValue("startDate").ToString("yyyy-MM-dd"); eventObj.end = item.GetPropertyValue("endDate").ToString("yyyy-MM-dd"); eventObj.title = item.Parent.Name; eventObj.url = item.Parent.Url; eventList.Add(eventObj); } return Json(eventList, JsonRequestBehavior.AllowGet); } 

让我与众不同的是将方法返回类型从ActionResult更改为JsonResult ,并将第二个参数“ JsonRequestBehavior.AllowGet ”添加到return函数中。

希望这可以帮助。