views:

48

answers:

2

Hi all

What is the best practice to carry out following workflow:

$("#myDiv").hide();
$.getJSON("url", function(data) { ... snorrr ... hours later ... });
$("#myDiv").slideDown();

This above mentioned sequence slides the div long befor hours have passed :-(

Thanks Er

+6  A: 

Just put the call in the callback.

$("#myDiv").hide();
$.getJSON("url", function(data) { 
    ... snorrr ... hours later ... 
    $("#myDiv").slideDown(); 
});

In addition you might want to show some indicator, so that the user knows that something is going on.

Felix Kling
+1  A: 

Put the slide down call at the end of the callback that handles the data.

This is the exact point of AJAX, Asynchronous so it doesn't wait and hang up all that time.

Sruly