JQuery how to resend form after ajax call success

I am using jQuery to execute form submission via ajax request. I use

form.submit(function() {
    if( success ) {
        return true;
    }

    validate(); //proceeds to an ajax call

    return false;
}

If the request is successful, I want to either continue submitting the form or the user callback. Therefore, if the user callback is undefined, I will submit the form when the form validation is successful (from my validation function).

config = {
    successCallback: function() {
        success = true;
        form.submit(); //does not work
    }
};

validate = function() {
    $.ajax(
        ...
        success: function(data) {
            //code logic
            config.successCallback();
        }
    );
};

The ajax success callback will call config.successCallback (), and if it is never canceled by the user, it will go to the normal view of the form. I tried using the instance variable (success) to make sure that "return true" goes to the default form view.

, . , "return false", , , . ( ).

- . , , , , , ajax , ajax .

+3
1

, success form[0].submit() , DOM jQuery ( DOM).

http://jsfiddle.net/J4nsx/

, jQuery validate .

+2

Source: https://habr.com/ru/post/1749485/


All Articles