jQuery BlockUI not working when called twice

906 views Asked by At

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();
        }
    });
});
1

There are 1 answers

0
detoro84 On BEST ANSWER

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();
        }
    });
});