Possible Duplicate:
Jquery: how to sleep or delay?
var main = $('#main_content');
main.append("<img id=\"throbber\" src='/pre_config/css/images/throbber.gif' alt='Loading. Please wait.' />");
sleep(3000);
$("#main_content").load("/pre_config/function.php?type="+type+"piz&count=1", successCallback );
I want to sleep for 3 seconds here
sleep is not defined
[Break on this error] sleep(3000);
func2
Use a javascript setTimeout()
.
setTimeout(function() {
$("#main_content").load("/pre_config/function.php?type="+type+"piz&count=1", successCallback );
}, 3000);
EDIT:
To use .delay()
, you would need to add the delayed code to an animation queue.
$("#main_content")
.delay(3000)
.queue(function( n ) {
$(this).load("/pre_config/function.php?type="+type+"piz&count=1", successCallback )
.dequeue();
});
Keep in mind that JavaScript is not only single threaded, but it shares the same thread with the page rendering. Therefore there are no in-built blocking functions in JavaScript, because that would make the page UI unresponsive.
You should consider using timers instead, using setTimeout()
, setInterval()
, or jQuery's delay()
. Check out @patrick's answer for a couple of examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With