javascriptjqueryloadblockuijquery-blockui

jQuery BlockUI not working when called twice


I'm using jQuery BlockUI Plugin on page loading (first thing):

<script>
    $.blockUI({ message: null });
</script>

And when everything loads, the whole page unblocks:

$(window).load(function () {
    $.unblockUI();
});

It works fine, but then I can't block ui again like this:

$("#buttonFoo").click(function(){
    $.blockUI(); //nothing happens
    doStuff(); //I want screen blocked while doing stuff
    $.unblockUI();
});

doStuff() is called but screen not blocked. Should I do anything else?

[EDIT]

It worked but as @GuruprasadRao said, $.unblockUI() didn't wait for doStuff() to finish. I solved like this:

$("#buttonFoo").click(function(){
      $.blockUI({
        onBlock: function() {
            doStuff();
            $.unblockUI();
        }
    });
});

Solution

  • It worked but as @GuruprasadRao said, $.unblockUI() didn't wait for doStuff() to finish. I solved like this:

    $("#buttonFoo").click(function(){
          $.blockUI({
            onBlock: function() {
                doStuff();
                $.unblockUI();
            }
        });
    });