tnchalise
tnchalise

Reputation: 1583

Jquery Full Calendar Events by ajax call

i am very much stacked to render events by updating my database entry. Initially, I have successfully rendered events through;

I have event array as:

{title: 'Available', start: new Date(2013, m, 05, 09,50), end: new
 Date(2013, m, 05, 10,00), allDay: false},{title: 'Available', start:
 new Date(2013, m, 04, 00,20), end: new Date(2013, m, 04, 00,50),
 allDay: false}

Which will be rendered in calander through:

events:[<?php echo $events?>]

Upto this, code works good and renders the event as per required.

After prev, next button is clicked, i have to render the events by updating the database. That is something like this:

 $('.fc-button-next span').live('click', function() {
        var calandar = $('#calandar');
         $.ajax({
            url: 'fetchEvents',
            dataType: 'JSON',
            type: 'POST',
            success: function(doc) {
                calandar.fullCalendar('removeEvents',event),
               calandar.fullCalendar( 'renderEvent',doc.events);
               calandar.fullCalendar('rerenderEvent',doc.events);
            }
        });
});

Where "fetchEvents" returns the same event format as before but in JSON form, like:

"{title: 'Available', start: new Date(2013, m, 05, 09,50), end: new Date(2013, m, 05, 10,00), allDay: false}"

Dont know, how to render JSON event objects on next-click event. That is i have to render completely new events through ajax call. Please suggest.

Solved:

Instead of events i have built, i create JSON events as suggested by Lukasz Koziara as in his first suggestion so that each time calendar event occurs, it acquires the eventSource to fetch the events. JSON EVENT

[{"title":"Available","start":"2013-06-06 05:20:00","end":"2013-06-06 05:50:00","allDay":false}]

Instead of events, i made a ajax call with in eventSources to get this type of JSON EVENTS. This looks like:

 eventSources: [{
                    url: 'fetchEvents',
                    type: 'POST'
                }]

So that, when calander renders for the first time or next,previous or today buttons are clicked, calander it self fetches events as specified by eventSources.

Upvotes: 1

Views: 5008

Answers (1)

Lukasz Koziara
Lukasz Koziara

Reputation: 4320

First suggestion: why not use one type of event source? For example use JSON feed - you can get events range by GET parameters start and end, so if you change month or view you can send from database appriopriate events.

Second suggestion: if you necessarily need two types of event sources, try use addEventSource / removeEventSource

Upvotes: 1

Related Questions