Passing functions as parameters of other functions
Hi, I have had some trouble with callback functions, and with waiting for ajax to complete before continuing a javascript code, and with passing functions as parameters to other functions. Any help would be appreciated.
The main goal I had was to use ajax to load a new set of html into a div, and then to preform another task AFTER all the elements had been defined. I've ended up with the following:
-
$('#apDiv1').load('AdminSetup.php', function(){stopAndContinue(loadedAdmin3(p_id), 15);});
stopAndContinueis a function like this:
-
function stopAndContinue(nextFunction, dummyvar){
//When we are done, load the next function
jQuery().ajaxStop(function(){
alert("Hi " + dummyvar);
jQuery().ajaxStop(function(){});//and in the 'callback' reset the ajaxStop event so that this function isn't called again.
nextFunction;
});
}
Basically, as far as I understand, it should attatch the next step (nextFunction) to the ajaxStop event, and also reset the ajaxStop event so that this function is not called again the next time an ajax operation is complete.
The altert is obviously for debugging.
However, even when nextFunction is commented out, it is still being called (!). I figured the function I am passing to stopAndContinue is being treated like a callback function, which would explain why nextFunction is being called before I get my alert.
Any ideas on what to do here? Is there a better way to do any of this?
Also, if I use stopAndContinue with another function as the parameter, it gets called (also when nextFunction is commented out), so it IS stopAndContinue that's the culprit, i think.
Thanks in advance
Matthew[/code]