[jQuery] Re: block on body onload, unblock on at the end of $(document).ready
There's no guarantee that the 'body' element will exist at the point you inserted the script, it should be right after the tag, not before. Usually there's nothing visible in the page before ready() fires, unless you're dealing with a very large document. On Feb 2, 8:44 pm, cambazz wrote: > well, what I want is document to be blocked before its ready. > and unblock when document is ready is finished > > so before I made a > > > $('body').block(); > > > > and at the end of the document ready > > $('body').unblock() > > it works, but I wonder if there is something i missed? > > best. > > On Feb 2, 11:11 am, Ricardo Tomasi wrote: > > > the 'onload' event actually fires after document ready - that's the > > reason doc ready exists! > > > What you want is to block *on* doc ready, and unblock after your ajax > > stuff is finished. As ajax is asynchronous, you'll have to keep track > > of every call to know when everything is done. > > > $(document).ready(function(){ > > > $.blockUI({ message: null }); > > var count = 0, > > ajaxCount = function(){ > > count++; > > if (count == 5) //total number of ajax calls > > $.unblockUI(); > > }); > > > $('xis').load('bla.py', function(){ > > //bla bla > > ajaxCount(); > > }); > > $.ajax({ etc etc, success: function(){ > > //blablabla etc etc > > ajaxCount(); > > }); > > ... and so on.. > > > }); > > > On Feb 1, 10:57 pm, cambazz wrote:> Hello, > > > > I would like to blockUI on body onload like: > > > > > > > > and when document ready finishes unblock, but unfortunately i can not > > > unblock it if I put blockUI on onload of body. > > > > My page makes few ajax calls and some processing on document ready, > > > and i want to blockUI until page finishes loading completely. > > > > Is there a solution, or a workaround? > > > > Best.
[jQuery] Re: block on body onload, unblock on at the end of $(document).ready
well, what I want is document to be blocked before its ready. and unblock when document is ready is finished so before I made a $('body').block(); and at the end of the document ready $('body').unblock() it works, but I wonder if there is something i missed? best. On Feb 2, 11:11 am, Ricardo Tomasi wrote: > the 'onload' event actually fires after document ready - that's the > reason doc ready exists! > > What you want is to block *on* doc ready, and unblock after your ajax > stuff is finished. As ajax is asynchronous, you'll have to keep track > of every call to know when everything is done. > > $(document).ready(function(){ > > $.blockUI({ message: null }); > var count = 0, > ajaxCount = function(){ > count++; > if (count == 5) //total number of ajax calls > $.unblockUI(); > }); > > $('xis').load('bla.py', function(){ > //bla bla > ajaxCount(); > }); > $.ajax({ etc etc, success: function(){ > //blablabla etc etc > ajaxCount(); > }); > ... and so on.. > > }); > > On Feb 1, 10:57 pm, cambazz wrote:> Hello, > > > I would like to blockUI on body onload like: > > > > > > and when document ready finishes unblock, but unfortunately i can not > > unblock it if I put blockUI on onload of body. > > > My page makes few ajax calls and some processing on document ready, > > and i want to blockUI until page finishes loading completely. > > > Is there a solution, or a workaround? > > > Best.
[jQuery] Re: block on body onload, unblock on at the end of $(document).ready
the 'onload' event actually fires after document ready - that's the reason doc ready exists! What you want is to block *on* doc ready, and unblock after your ajax stuff is finished. As ajax is asynchronous, you'll have to keep track of every call to know when everything is done. $(document).ready(function(){ $.blockUI({ message: null }); var count = 0, ajaxCount = function(){ count++; if (count == 5) //total number of ajax calls $.unblockUI(); }); $('xis').load('bla.py', function(){ //bla bla ajaxCount(); }); $.ajax({ etc etc, success: function(){ //blablabla etc etc ajaxCount(); }); ... and so on.. }); On Feb 1, 10:57 pm, cambazz wrote: > Hello, > > I would like to blockUI on body onload like: > > > > and when document ready finishes unblock, but unfortunately i can not > unblock it if I put blockUI on onload of body. > > My page makes few ajax calls and some processing on document ready, > and i want to blockUI until page finishes loading completely. > > Is there a solution, or a workaround? > > Best.
[jQuery] Re: block on body onload, unblock on at the end of $(document).ready
> I would like to blockUI on body onload like: > > > > and when document ready finishes unblock, but unfortunately i can not > unblock it if I put blockUI on onload of body. > > My page makes few ajax calls and some processing on document ready, > and i want to blockUI until page finishes loading completely. > > Is there a solution, or a workaround? Why can't you unblock it? It's recommended that you do not use an inline event like onload. Instead, use jQuery's ready event: $(document).ready(function() { $.blockUI({ message: null }); // do stuff $.unblockUI(); }); Except in your case, $.unblockUI is probably called from an ajax callback.