1

I have a problem with the events in my fullCalendar object not showing when using ajax to fetch the data from my JSON feed. I believe the JSON format is proper though since the output from JSON.aspx is:

[{"id":1,"title":"TESTTITLE","info":"INFOINFOINFO","start":"2012-08-20T12:00:00","end":"2012-08-20T12:00:00","user":1}]

I used Firebug and it seems like the JSON feed is not getting fetched properly?

When I add the upper JSON-feed directly in the events it displays properly.

(Edit) The JSON response is now working, although the events are still not displayed in fullcalendar.

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<calevent> 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();
   }
}

And my Site.master

<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />    
<link href='fullcalendar/fullcalendar.css' rel='stylesheet' type='text/css' />
<script src='jquery/jquery-1.7.1.min.js' type='text/javascript'></script>
<script src='fullcalendar/fullcalendar.js' type='text/javascript' ></script>
<script type="text/javascript">
     $(document).ready(function () {
         $('#fullcal').fullCalendar({

            eventClick: function() {
                alert('a day has been clicked!');
            },
          events: 'JSON.aspx' 
         })
     });
</script>

I've been scanning related questions for days but none of them seems to fix mine...

Mix
  • 117
  • 2
  • 11
  • Have you tried accessing the JSON directly or using FireBug to see what the output actually is? – naspinski Sep 09 '12 at 13:37
  • I accessed it directly through JSON.aspx. And used FireBug to check Site.Master to see if it it was fetched. – Mix Sep 09 '12 at 13:43

1 Answers1

2

Why are your calls so complicated? Try this for now:

$('#fullcal').fullCalendar({     
    events: 'JSON.aspx',
    eventClick: function (calEvent, jsEvent, view) {
        alert('a day has been clicked!');
    }
}); 
naspinski
  • 34,020
  • 36
  • 111
  • 167
  • Thank you! I can now see the JSON post in Site.Master. It still doesn't show up in the calendar though. – Mix Sep 09 '12 at 14:28
  • The JSON response: [{"id":1,"title":"TESTTITLE","info":"INFOINFOINFO","start":"2012-08-20T12:00:00","end":"2012-08-20T12:00:00","user":1}] – Mix Sep 10 '12 at 10:50
  • 1
    It's now working. The problem was a faulty js-file! Thank you for your help! – Mix Sep 10 '12 at 11:17