My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 1916: Better handle failed AJAX calls
2 people starred this issue and may be notified of changes. Back to list
Status:  ExportedToGithub
Owner:  ----
Closed:  Aug 2015


Sign in to add a comment
 
Reported by sga...@gmail.com, Jul 12, 2013
Hi, first of all, thanks for this great plugin !

I have the following issue, which is easy to reproduce :

I'm fetching a private calendar from a local web server, as well as a google public calendar (french holidays) from the internet.

    $agenda.fullCalendar( 'addEventSource', {
        url: myUrl
    });

    $agenda.fullCalendar( 'addEventSource', {
        url: 'https://www.google.com/calendar/feeds/fr.french%23holiday%40group.v.calendar.google.com/public/basic'
    });

This works great, except in the following situation :

If there is no internet access, the whole calendar fails to render, local events are not even displayed.

I can see from the console that the google GET fails instantaneously, and that the local GET succeeds, but I haven't been able to manage trapping the error. This does not work :

    $agenda.fullCalendar( 'addEventSource', {
        url: 'https://www.google.com/calendar/feeds/fr.french%23holiday%40group.v.calendar.google.com/public/basic',
        error: function() {
            alert('something went wrong');
        }
    });

Any hint on how to force display of local events in case the google service is unavailable ?


Jul 12, 2013
#1 sga...@gmail.com
Okay, I found the reason and a reasonable solution.

Reason : in the case the server cannot be reached, there's no callback to ajax error(), complete(), success(). This leaves fullCalendar in a state where the stack of requests is unprocessed, and events stays un-rendered (if I may say).

Solution : line 993 onward ->
------------------------------------------------------------------
// Make the ajax call
var request = $.ajax($.extend({}, ajaxDefaults, source, {
        data: data
})).done(function(events, textStatus, jqXHR) {
    // success
    events = events || [];
    var res = applyAll(success, this, arguments);
    if ($.isArray(res)) {
        events = res;
    }
    callback(events);
}).fail(function(jqXHR, textStatus, errorThrown) {
    // error
    applyAll(error, this, arguments);
    callback();
}).always(function(events, textStatus, errorThrown) {
    // complete
    applyAll(complete, this, arguments);
    popLoading();
});

// Test if the ajax call was successful after 5000ms
setTimeout(function(){
    if (request.state() == 'pending') {
        request.abort();
    }
}, 5000);
------------------------------------------------------------------

The request.abort() call will trigger the error()/fail() callback and put fullCalendar back in a correct state.

Don't know if that's a good implementation, but that seems to solve the issue, so hopefully that will help to tackle it gracefully.

Aug 24, 2013
Project Member #2 adamrs...@gmail.com
(No comment was entered for this change.)
Summary: Better handle failed AJAX calls (was: Uncatched error when fetching Google Calendar events)
Status: Accepted
Labels: Type-Feature
Aug 21, 2015
Project Member #3 adamrs...@gmail.com
Discussion for this issue has moved to the following URL:
https://github.com/fullcalendar/fullcalendar/issues/2183

This is because Google Code is shutting down. Apologies if you are being pestered with these notifications. This is a one-time event.

Happy coding,
Adam
Status: ExportedToGithub
Sign in to add a comment

Powered by Google Project Hosting