views:

210

answers:

4

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
+3  A: 

Is this SO post what you're looking for?

Chris Thompson
You should have posted this as a comment.
ChrisF
I tried delay on load by load.delay(3000).... but it failed
Matt
@ChrisF, perhaps...my bad!
Chris Thompson
+5  A: 

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();
});
patrick dw
+1... I cited your examples in my answer :) These should help the OP.
Daniel Vassallo
+2  A: 

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.

Daniel Vassallo
A: 

you should search before post

http://stackoverflow.com/questions/2939980/jquery-how-to-sleep-or-delay

.delay()

http://api.jquery.com/delay/

balexandre
`.delay()` won't work here, at least not without utilizing `.queue()` in conjunction.
patrick dw