I have a code snipet like this:
var nbrPrevArt = $("#accordion > div .accordionPanel").size();
var processing = false;
if (nbrPrevArt == 0) {
processing = true;
getArticlesPreview();//Fetches articles first
}
//loop that makes the browser to wait until finishes "getArticlesPreview()"
while(!processing)
{
}
//getArticlesPreview() is finished now we can safely execute this step
$.ajax({
type: "GET",
url: "http://mydomain.com/somepage.htl",
success: function(data) { alert(data);}
});
//-----------------------------------
function getArticlesPreview()
{
//lenghty operation
processing = false;
}
don’t look much practical because i am using a loop to make it wait until the function is competely executed to perform next step.
Is there a way to define a callback message to be called when the first operation is done and the have my second step ( the $.ajax call) inside it to run properly?
Thank you in advance!
Teixeira
You could create your callback yourself, by using the
applyfunction. You juste have to add acallbackparameter to getArticlesPreview, and put the function inside this callback.This could look like this :