views:

298

answers:

2

can somebody tell me how to populate "jquery fullcalendar" events using ajax.

There is no setter method provided in fullcalendar to set ajax response (which is Json object) after calendar object loads. Is there any way to feed data after calendar object loads?

In my case very first time I provide data in fullcalendar "event:" property and it is working fine. But when I press next or previous to switch one month to another, I'm unable to feed data into that.

Thnx in advance

+1  A: 

Rather than fetching the events by Ajax and then putting them in the calendar, you can use the fullcalendar to do all of the Ajax for you:

$('#calendar').fullCalendar({
    events: "/myfeed.php"
});

Then the correct events will be fetched according to the range of dates the user is viewing. See the fullcalendar documentation for more info.

theycallmemorty
Thanks theycallmemorty, but I can't load all data at once while calendar object loads. I need to refetch data for each month or week whenever user clicks on "next" or "prev" buttons or change views.
Bhupi
The fullcalendar control will handle that for you in the form of the `start` and `end` parameters. Every time the user changes views or clicks prev or next the control will send a request to your server.
theycallmemorty
can you pls give some example of server side response when the above url will fire? Thanks
Bhupi
@Bhupi: What language are you using for your back end?
theycallmemorty
J2EE using spring
Bhupi
Please give me example of json response what should I keep in start:, end: , and I guess title will be plain string.I've used same method what you suggest but fullcalendar does not show anything on any view
Bhupi
`start` and `end` are timestamps. Try this in Java: java.sql.Timestamp timeStampDate = new Timestamp(date.getTime()); and use timeStampDate.toString(); to convert that into a string that can be put into your json response.
theycallmemorty
Thanks Morty, I'm trying this
Bhupi
+1  A: 

in ASP.NET MVC View:

$('#calendar').fullCalendar({
            theme: true,
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            events: "/Calendar/GetEvents/"});

Contoller:

public JsonResult GetEvents()
    {
        List<DAL.VwMeeting> allMeeting = meetingRepository.GetAll();
        var eventList = from e in allMeeting
                        select new
                        {
                            url=(e.MeetingOccurID).ToString(),
                            title = e.MeetingTitle,
                            start = ConvertToUnixTimestamp((DateTime)e.MeetingOccurStartDate),
                            end = ConvertToUnixTimestamp((DateTime)e.MeetingOccurEndTime),
                            allDay = false
                        };
        return Json(eventList.ToArray());
    }

or you can use:

$('#calendar').fullCalendar('refetchEvents');

after each event handle

Akyegane
Please give me example of json response what should I keep in start:, end: , and I guess title will be plain string. I've used same method what you suggest but fullcalendar does not show anything on any view. I'm using JSP and servlet on server end.Thanks
Bhupi
Sorry Bhupi,I'm .NET developer,you can see this tutorials http://weblogs.asp.net/gunnarpeipman/archive/2010/02/03/using-fullcalendar-jquery-component-with-asp-net-mvc.aspx,http://szahariev.blogspot.com/2009/08/jquery-fullcalendar-and-aspnet-mvc.htmlor you can see Fullcalendar: http://arshaw.com/js/fullcalendar/examples/agenda-views.html
Akyegane