Merging $.get and $.ready
Posted
by
cwolves
on Stack Overflow
See other posts from Stack Overflow
or by cwolves
Published on 2012-04-10T17:08:35Z
Indexed on
2012/04/10
17:28 UTC
Read the original article
Hit count: 142
Put simply I have an ajax call that sometimes completes before the page is loaded, so I tried wrapping the callback in $( fn )
, but the callback doesn't fire if the page is loaded... Anyone have a good solution to this?
$.get( '/foo.json', function( data ){
$( function(){
// won't get here if page ready beats the ajax call
// process data
$( '.someDiv' ).append( someData );
} );
} );
And yes, I know that if I flipped the order of those it would always work, but then my ajax calls would be needlessly deferred until the document is ready.
© Stack Overflow or respective owner