JQuery Form plugin ajaxSubmit

I have the following code associated with a button click event:

function submitForm() {

    var $submitOK = false;
    $('#form1').ajaxSubmit({
        beforeSubmit: function() {
            $submitOK = $('#form1').valid();
            return $submitOK;
        },
        success: function(html, status) {
            $("#response").text(html.substring(1, html.length - 1));            
        }
    });

    if ($submitOK) {
        processForm1();
    }

    return $submitOK;
}

      

How will the ajaxSubmit and beforeSubmit callbacks be synchronized - will the beforeSubmit callback always return before execution returns from ajaxSubmit ()?

The code behaves as desired - returns $ submitOK equal to the result of $ ('# form1'). valid (), but I wanted to make sure this is deterministic behavior.

Thank.

+2


source to share


1 answer


Yes, beforeSubmit will always return in the first place, what it's intended is the pre-submit hook.



+1


source







All Articles