function load_result()
{
$.getJSON( "http://somesite.com/loadresult.php", function(data) {
if( data == undefined || data == null )
{
console.log( "no data" );
clearTimeout( lr_timeout );
lr_timeout = setTimeout( "load_result()", 2000 );
return;
}
insert_result_price( data );
clearTimeout( lr_timeout );
lr_timeout = setTimeout( "load_result()", 50 * ( Math.random() * 10 ) );
} );
}
and lr_timeout is defined globally and the load_result function is kicked off initially in the document.ready function. The problem is that the function doesn’t always run. I’ll watch it in Firebug and I have another function that’s set on a setInterval that always works.
Ideas?
Is your other
setTimeoutfunction (the one that always works) also inside a$.getJSON? If so, does it call it on the same URL (http://somesite.com/loadresult.phpin your example, but I’m sure it’s different in real life)?It’s possible that
http://somesite.com/loadresult.phpis a flaky resource, and your inconsistent results are due to that resource, notsetTimeout. Of course, if they’re both using that same resource, then that couldn’t be the problem.