Multiple blocks in jquery ui blocker?

I am using this plugin.

However, it seems global variables are being used

$.blockUI();
$.unblockUI();

I have different instances of this block.

 $(document).ajaxStart(function (e)
 {
          $.blockUI(); //setup with a loading msg.
  });

 $(document).ajaxStop(function (e)
        {       
            $.unblockUI();

        })


var ajax = // ajax setup stuff


// 1.5 way of doing it
ajax .success(function (response)
            {
               var valid = checkIfValid(response); // check if valid
               if(valid)
               {
                      $.blockUI(); // setup with a save message
               }

            });

So that’s what I have. I put

$.blockUI();

to keep it simple without parameters, but in my real code I have messages and other parameters.

So now the problem is that after success is completed, ajax stop calls and unlocks everything. I just want the one that was launched at the beginning of ajax not to get rid of what was in the actual.

Therefore, I need different instances.

+3
source share
1 answer

, , block div, " ", div DOM. :

$(document).ajaxStart(function (e) {
    /* Create a <div> that will contain the blocking elements: */
    $("<div id='ajax-block' style='position:fixed;width:100%;height:100%' />")
        .appendTo("body").block()
});

$(document).ajaxStop(function (e) {
    /* Remove the page block specific to the ajax request: */       
    $("#ajax-block").remove();
});

- , ( id div remove().

+5

All Articles