jnb
jnb

Reputation:

jQuery ajaxForm beforeSubmit fires on document.ready

I have the following code:

$("#forma_mod_uid").livequery( function (){
       $("#forma_mod_uid").ajaxForm({
                beforeSubmit: mcargando("#cargando2"),
                target:'#mod_2',
                success: ocargando("#cargando2")
       })
});

The mcargando passes the div which will contain a spinner img, and then on success ocragando will hide that div, problem is that beforeSubmit is firing beforeSubmit on document ready.

function mcargando(id_div){
    if (id_div==null){ var id_div="#cargando";}
    $(id_div).livequery(function (){$(id_div).show();});
}

Upvotes: 2

Views: 2657

Answers (1)

Paolo Bergantino
Paolo Bergantino

Reputation: 488454

beforeSubmit: mcargando("#cargando2"),

Should be:

beforeSubmit: function() { mcargando("#cargando2") },

And

success: ocargando("#cargando2")

Should be:

success: function() { ocargando("#cargando2") }

As you have it right now, you are calling the functions. The only way you could use the code you have there without calling the function is if you did beforeSubmit: mcargando, but since you need to pass a variable to the function just wrap the call in a function to be able to do it and you should be fine.

Upvotes: 3

Related Questions