Based on your initial code you can do this:
function loading(foo) {
$("#ajaxContent").slideToggle("normal", function() {
$("#ajaxLoader").toggle();
if ($.isFunction(foo)) {
foo.call();
}
});
}
$("#searchBar > button").click(function() {
loading(function() {
$.get("ajax/list.php", function(data){
$("#ajaxContent").html(data);
loading();
});
});
});
On Jan 8, 9:00 pm, rics <[EMAIL PROTECTED]> wrote:
> I did it using ajaxStart() and ajaxStop(), but I still want to know if
> I can set a callback to a custom function, for learning reasons. If
> you can help, thanks.
>
> :D
>
> Here is the final code...
>
> $("#ajaxContent").ajaxStart(function(){
> $(this).slideToggle("normal");
> $("#ajaxLoader").toggle();
> });
>
> $("#ajaxContent").ajaxStop(function(){
> $(this).slideToggle("normal", function(){
> $("#ajaxLoader").toggle();
> });
> });
>
> $("#searchBar > button").click(function() {
> $.get("ajax/list.php", function(data){
> $("#ajaxContent").html(data);
> });
> });
>
> On Jan 8, 1:38 pm, rics <[EMAIL PROTECTED]> wrote:
>
> > Hello people,
>
> > How can I force some code to run only when the execution of other
> > function finish? Look my code:
>
> > function loading() {
> > $("#ajaxContent").slideToggle("normal", function() {
> > $("#ajaxLoader").toggle();
> > });
> > }
>
> > $("#searchBar > button").click(function() {
> > loading();
> > $.get("ajax/list.php", function(data){
> > $("#ajaxContent").html(data);
> > loading();
> > });
> > });
>
> > In the second block of code I want the $.get to execute only when the
> > function loading(), that was coded by me, finish to execute. I mean,
> > when the #ajaxLoader is show up.
>
> > How can I do something like that?