即使正确的JSON提要,fullCalendar事件也不会显示

作为一堆其他人,我在将日历中的JSON Feed事件呈现时遇到问题。 问题通常是错误的JSON格式化,但事实并非如此,因为我已经使用JSONlint对其进行了validation,并在Site.Master中对JSON提要进行了硬编码,结果为正。

FireBug正确获取JSON响应,但仍未显示在fullCalendar中。 我没有想法。

FireBug响应:[{“id”:1,“title”:“TESTTITLE”,“info”:“INFOINFOINFO”,“start”:“2012-08-20T12:00:00”,“end”:“2012 -08-20T12:00:00″ , “用户”:1}]

JSON.aspx

public partial class JSON : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // Get events from db and add to list. DataClassesDataContext db = new DataClassesDataContext(); List eventList = db.calevents.ToList(); // Select events and return datetime as sortable XML Schema style. var events = from ev in eventList select new { id = ev.event_id, title = ev.title, info = ev.description, start = ev.event_start.ToString("s"), end = ev.event_end.ToString("s"), user = ev.user_id }; // Serialize to JSON string. JavaScriptSerializer jss = new JavaScriptSerializer(); String json = jss.Serialize(events); Response.Write(json); Response.End(); } } 

的Site.Master

      $(document).ready(function () { $('#fullcal').fullCalendar({ eventClick: function() { alert('a day has been clicked!'); }, events: 'JSON.aspx' }) });  

我已经扫描了几天的相关问题,但似乎没有人能解决我的问题……

试试这个,你必须在aspx文件中有一个webmethod,fullcalendar可以异步调用

  $(document).ready(function () { $('#fullcal').fullCalendar({ eventClick: function() { alert('a day has been clicked!'); }, events: function (start, end, callback) { $.ajax({ type: "POST", //WebMethods will not allow GET url: "json.aspx/GetEvents", //url of a webmethod - example below data: "{'userID':'" + $('#<%= hidUserID.ClientID %>').val() + "'}", //this is what I use to pass who's calendar it is //completely take out 'data:' line if you don't want to pass to webmethod - Important to also change webmethod to not accept any parameters contentType: "application/json; charset=utf-8", dataType: "json", success: function (doc) { var events = []; //javascript event object created here var obj = $.parseJSON(doc.d); //.net returns json wrapped in "d" $(obj.event).each(function () { //yours is obj.calevent events.push({ title: $(this).attr('title'), //your calevent object has identical parameters 'title', 'start', ect, so this will work start: $(this).attr('start'), // will be parsed into DateTime object end: $(this).attr('end'), id: $(this).attr('id') }); }); callback(events); } }); } }) 

然后这将在json.aspx中

 [WebMethod(EnableSession = true)] public static string GetEvents(string userID) { DataClassesDataContext db = new DataClassesDataContext(); List eventList = db.calevents.ToList(); // Select events and return datetime as sortable XML Schema style. var events = from ev in eventList select new { id = ev.event_id, title = ev.title, info = ev.description, start = ev.event_start.ToString("s"), end = ev.event_end.ToString("s"), user = ev.user_id }; // Serialize to JSON string. JavaScriptSerializer jss = new JavaScriptSerializer(); String json = jss.Serialize(events); return json; }