我只是想做一些非常简单的事情开始。jquery FullCalendar使用MVC和JSON
我使用了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 = "<p>This is just a fake description for the Free Pizza.</p><p>Nothing to see!</p>", 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 = "<p>This is just a fake description for the Free Pizza.</p><p>Nothing to see!</p>", 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/"}
我看到别人也有类似的问题,但我没有看到关于如何使用AJAX的例子和这个日历的JSON。
我也尝试使用eventSources:文档/示例具有相同的结果。
更新:
我更新了我的代码,基于我试过的不同事情。仍然没有运气。我看过日期格式。我试过了系统生成的日期,但是我所看到的一切似乎都指向了基于字符串的日期(这是我在更新的代码中尝试过的)。不幸的是,这仍然不起作用(至少对我而言)。
仍在寻求帮助。
您的后端'Datetime'格式在javascript中无效 – charlietfl 2015-01-04 15:41:47
@charlietfl - 这样做的正确方法是什么? – webdad3 2015-01-04 15:52:35
从服务器发送正确的格式 – charlietfl 2015-01-04 15:53:09