我在webForms (ASPX)页面中有一个jQuery日历。我理解json符号,它是相当简单的使用键值对。我的日历有一个可以输入json的事件参数。
请原谅我的用词
events: [
{
title: 'All Day Event',
start: new Date(y, m, 1),
backgroundColor: "#f56954",
borderColor: "#f56954"
},
{
title: 'Long Event',
start: new Date(y, m, d - 5),
end: new Date(y, m, d - 2),
backgroundColor: "#f39c12",
borderColor: "#f39c12"
},
{
title: 'Meeting',
start: new Date(y, m, d, 10, 30),
allDay: false,
backgroundColor: "#0073b7",
borderColor: "#0073b7"
},
{
title: 'Lunch',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
allDay: false,
backgroundColor: "#00c0ef",
borderColor: "#00c0ef"
},
],
此时,我不希望用户与页面交互。我只关心填充这个jQuery json来填充标题,开始日期和结束日期从我的。net对象数据源。没什么特别的,我不介意在前端显示为json的信息。这个应用程序在登录后,所以没有一个页面是面向公众的。
我从来没有使用SQL Server填充json数据。我读过一些线程,似乎解决方案更多的情况下,信息被传递到前端,然后持久化到后端。
我发现这个线程问同样的问题,但没有答案。jquery-week-calendar-asp.net
谁能给我指个正确的方向?我正在摸索着找到合适的工具来完成这项工作。您需要通过AJAX在服务器上调用一个方法。该方法应该返回JSON,如下所示:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Event> GetEvents()
{
// return someDbQueryToRetrieveYourEvents().ToList();
}
EDIT -添加日历插件特定的AJAX调用
AJAX可能是这样的:
$(document).ready(function() {
$('#calendar').weekCalendar({
data: function(start, end, callback) {
$.getJSON("calendarevents.json", {
start: start.getTime(),
end: end.getTime()
}, function(result) {
callback(result);
});
}
});
});
这有帮助吗?