Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
$(document).ready() - $.isReady bug
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Giulio  
View profile  
 More options Mar 13 2008, 1:40 pm
From: Giulio <giulio.l.d...@gmail.com>
Date: Thu, 13 Mar 2008 10:40:39 -0700 (PDT)
Local: Thurs, Mar 13 2008 1:40 pm
Subject: $(document).ready() - $.isReady bug
Hi,

We have spent some time racking our heads why $(document).ready()
wasn't always firing and we finally found it.

The ready() function checks jQuery.isReady. If true, it fires straight
away, if false, it gets queued and fired once the document is ready.

This is fine if you have a page which registers a ready function on
the initial load of the page. At this point jQuery hooks itself up to
capture the documents ready event, fires your function and also sets
jQuery.isReady to true.

However, if you have a page with jQuery on it and don't register
anything on the first load, then jQuery.isReady is left to be false.
Then you load a script via ajax which calls $
(document).ready(functrion(){/*do stuff*/})   but it won't fire. Why?
because, the page is already loaded, so the document ready event
doesn't fire and hence doesn't set jQuery.isReady to true. Registering
a function at this point get's added to  jQuery.readyList  but it is
never run.

For now I have fixed this by appending this line to the end of the
jQuery file which registers a dummy function.

//////////////////////////
$(document).ready(function(){});
//////////////////////////

This function does nothing other than make sure jQuery hooked up the
ready event in the case that no ready function was externally queued
on jQuery.readyList on the initial page load. There may be a better
fix for this by a jQuery guru, buth this does the trick for now.

Giulio


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Resig  
View profile  
 More options Mar 13 2008, 1:51 pm
From: "John Resig" <jere...@gmail.com>
Date: Thu, 13 Mar 2008 13:51:46 -0400
Local: Thurs, Mar 13 2008 1:51 pm
Subject: Re: [jquery-dev] $(document).ready() - $.isReady bug
Ok, I understand what you're shooting for - could you file a bug?
http://dev.jquery.com/

I'm a little bit confused, though. In which situation are you loading
jQuery before the document is ready - NOT using a document ready
handler on load - but using document ready handler at some later
point?

--John


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Clay  
View profile  
 More options Mar 13 2008, 3:10 pm
From: Steve Clay <st...@mrclay.org>
Date: Thu, 13 Mar 2008 15:10:52 -0400
Local: Thurs, Mar 13 2008 3:10 pm
Subject: Re: [jquery-dev] Re: $(document).ready() - $.isReady bug

John Resig wrote:
> I'm a little bit confused, though. In which situation are you loading
> jQuery before the document is ready - NOT using a document ready
> handler on load - but using document ready handler at some later
> point?

He has a race condition. I think he's loading a script via AJAX that may
or may not be executed by the time the original page is ready. If this
is the case, there's a simple solution:

// page
var ready = false;
$(function () { ready = true; });

// script returned by AJAX:
function doStuff() { /* do stuff */ }
if (ready)
   doStuff()
else
   $(doStuff);

I don't think this problem needs to be solved by jQuery.

--
Steve Clay
http://mrclay.org/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ariel Flesler  
View profile  
 More options Mar 13 2008, 5:11 pm
From: Ariel Flesler <afles...@gmail.com>
Date: Thu, 13 Mar 2008 14:11:40 -0700 (PDT)
Local: Thurs, Mar 13 2008 5:11 pm
Subject: Re: $(document).ready() - $.isReady bug
The thing is that the bindReady function is lazy (if I'm not
mistaken), so it doesn't run until the first call to document.ready.
if your first call comes after the document is ready, it doesn't run.
Right ?

Cheers

--
Ariel Flesler
http://flesler.blogspot.com

On 13 mar, 16:10, Steve Clay <st...@mrclay.org> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Klaus Hartl  
View profile  
 More options Mar 13 2008, 7:39 pm
From: Klaus Hartl <klaus.ha...@googlemail.com>
Date: Thu, 13 Mar 2008 16:39:15 -0700 (PDT)
Local: Thurs, Mar 13 2008 7:39 pm
Subject: Re: $(document).ready() - $.isReady bug
On Mar 13, 6:51 pm, "John Resig" <jere...@gmail.com> wrote:

> Ok, I understand what you're shooting for - could you file a bug?http://dev.jquery.com/

> I'm a little bit confused, though. In which situation are you loading
> jQuery before the document is ready - NOT using a document ready
> handler on load - but using document ready handler at some later
> point?

I ran into the same problem the other day but didn't fully understand
what was wrong until now.

We are using a bottom script approach without ever using the DOM ready
event. Some datepicker stuff is loaded via Ajax later on, but because
the UI datepicker uses the ready event at some point to add some
required elements it'll never get properly initialized. I filed a
separate ticket for this already.

There may be other plugins relying on the ready event as well. I think
if at all possible that should be avoided in plugins.

http://dev.jquery.com/ticket/2481

--Klaus


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Giulio  
View profile  
 More options Mar 14 2008, 7:56 am
From: Giulio <giulio.l.d...@gmail.com>
Date: Fri, 14 Mar 2008 04:56:29 -0700 (PDT)
Local: Fri, Mar 14 2008 7:56 am
Subject: Re: $(document).ready() - $.isReady bug
Klaus, using the datepicker is exactly how we found the bug. We have a
page which loads and doesn't register any $(document).ready()
functions. Then via ajax we load a calander if necessary but it wasn't
being initialised because of the reasons discussed above. I think it
is perfectly valid for any plugin / control developer to register a
ready function and expect it to fire no matter how it got there.

Giulio

On Mar 13, 11:39 pm, Klaus Hartl <klaus.ha...@googlemail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Clay  
View profile  
 More options Mar 14 2008, 11:31 am
From: Steve Clay <st...@mrclay.org>
Date: Fri, 14 Mar 2008 11:31:44 -0400
Local: Fri, Mar 14 2008 11:31 am
Subject: Re: [jquery-dev] Re: $(document).ready() - $.isReady bug

Giulio wrote:
> is perfectly valid for any plugin / control developer to register a
> ready function and expect it to fire no matter how it got there.

I think there are two ways to think about this:

1. If users consider ready() a replacement for window.onload (as the
docs say), then jQuery isn't broken; after all, if you assign functions
to window.onload after the event has occurred they'll never be called
either!

2. With minor mods we could make ready() so that it's a reliable way to
call a function as soon as possible. *Any* time you call it, that
function is guaranteed to fire.

#1 appeals to the strictness nerd in me; the user should recognize that
they're creating a race condition by calling code via AJAX and manually
prepare for it.

But if the modification was small and wouldn't have a performance hit, I
think #2 would make ready() more useful and eliminate hours of user
frustration in cases like this.

--
Steve Clay
http://mrclay.org/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Giulio  
View profile  
 More options Mar 14 2008, 12:37 pm
From: Giulio <giulio.l.d...@gmail.com>
Date: Fri, 14 Mar 2008 09:37:56 -0700 (PDT)
Local: Fri, Mar 14 2008 12:37 pm
Subject: Re: $(document).ready() - $.isReady bug
Interesting because number 2 is technically already there and hence
assumed IF and only IF something first registers with the ready event.
jQuery checks for isReady and if it is it gets fired immediately. So,
why not always do this?

Froma  control  developers point of view they need something to happen
when the page is ready to (usually) initialise things. In the case of
a blank page with the control already there, you do want to wait for
the browser load event. If the control is loaded later, it still needs
to fire, so why have every control developer code the what if scenario
and not just have jQuery handle it? Especially considreing it was
coded to do it this way in the first place assuming something is
registered with ready.

On Mar 14, 3:31 pm, Steve Clay <st...@mrclay.org> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diego Perini  
View profile  
 More options Mar 14 2008, 1:17 pm
From: Diego Perini <diego.per...@gmail.com>
Date: Fri, 14 Mar 2008 10:17:10 -0700 (PDT)
Local: Fri, Mar 14 2008 1:17 pm
Subject: Re: $(document).ready() - $.isReady bug
Giulio,
effectively the "doScroll('left')" trick implemented in jQuery
provisions for that too...

Look at this for example, and use this meanwhile if it solves:

// use the name that best fits you
function isDOMReady() {
    try {
        document.documentElement.doScroll('left');
    } catch (e) {
        return false;
    }
    return true;

}

You are probably right in assuming that jQuery should, in any case,
write/save somewhere that the loading process was completed,
even if nobody asked for it.

Diego Perini

On 14 Mar, 17:37, Giulio <giulio.l.d...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Giulio  
View profile  
 More options Mar 14 2008, 1:45 pm
From: Giulio <giulio.l.d...@gmail.com>
Date: Fri, 14 Mar 2008 10:45:52 -0700 (PDT)
Local: Fri, Mar 14 2008 1:45 pm
Subject: Re: $(document).ready() - $.isReady bug
Diego, thanks dor the tip, for now, I'll stick to appending this to my
jQuery file as it is simpler:

 $(document).ready(function(){});

Giulio

On Mar 14, 5:17 pm, Diego Perini <diego.per...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google