Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you delay AJAX requests (for month change) in jQuery FullCalendar?

I am using jquery fullcalendar which works great. The one issue I have is if you click forward or backward to move through multiple months very quickly, it still tries to fire off multiple ajax requests and it doesn't wait to see if you actually "settle" down on that month.

I basically want it to wait for 1 second before it fires off an ajax event to make sure the user isn't going to click next again.

Is this possible in jquery full calendar? I would have thought a plugin with such following and other advanced features would have this

like image 840
leora Avatar asked Nov 13 '22 07:11

leora


1 Answers

JQuery has a whole range of Ajax event handlers like ajaxSend, ajaxPrefilter and ajaxStart.

Using the ajaxPrefilter() method you could probably capture the Ajax request before it's sent, delay it and if a click event on the month navigator buttons isn't detected within the timeframe send the request, otherwise abort it.

This is a bit of a contrived example, but something along these lines might be close to what you want:

var enableRequest = true;

$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
  // Modify options, control originalOptions, store jqXHR, etc

    if (!enableRequest ){
        jqXHR.abort();
    }
});

$('span.fc-button-prev, span.fc-button-next').click(function(){
    enableRequest = false;
    setTimeout("setEnabled()", 2000)
});


function setEnabled()
{
    enableRequest = true;
});
like image 177
Phil.Wheeler Avatar answered May 23 '23 06:05

Phil.Wheeler