我只是想做一些非常簡單的事情開始。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