Search code examples
jqueryajaxblockui

Disable BlockUI for certain ajax calls


I am using the brilliant BlockUI, and have set it up using the default

$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);

Which is great - except when I add a autocomplete element on the page, and then the blockUI kicks in as soon as the user starts typing. Rather than explicitly set what ajax calls to launch the block UI can anyone think of a way to disable blockUI for certain ajax functions?


Solution

  • You could do something like this:

    var dontBlock = false;
    
    $(document).ajaxStart(function(){
        if(!dontBlock)
            $.blockUI();
    }).ajaxStop($.unblockUI);
    
    // And in the ajax methods (to be excluded), set dontBlock accordingly
    
    $('#autocomplete').keydown(function(){
        dontBlock = true;
        $.ajax({
            // url, data etc.
            success: function(){ dontBlock = false; }
        });
    });