Using the correct jQuery submitHandler validation module

first some documentation from the jQuery validation plugin:

"Use submitHandler to handle something, and then use the default submit. Note that the" form "refers to the DOM element, so the validation does not start again."

submitHandler: function(form) {
    $.ajax({
        type: 'POST',
        url: form.action,
        data: 'current_password=' + form.current_password + '&new_password=' + form.new_password,
        success: function(){
            alert("succes");
        }
    });
}

So, naturally, my ingenious part of the code does not work. I am trying to access the action attribute and two input fields from a form object, with no luck. How am I supposed to do this?

+3
source share
1 answer

Try this instead:

submitHandler: function(form) {
    $.ajax({
        type: 'POST',
        url: $(form).attr('action'),
        data: { current_password : form.current_password.value,
                new_password: form.new_password.value }
        success: function(){
            alert("succes");
        }
    });
}

, toString , .value, . data , , , , , & , .

+8

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


All Articles