jQuery-Form-Validator Send ajax on onSuccess

jQuery-Form-Validator Send ajax on onSuccess

hello
Sorry for my very bad English .
I uses plugins jQuery-Form- validator (http://formvalidator.net/ )
And I want when passing validation on kalbasks onsuksess function to send the request. I got here tacos code

  1. $(document).ready(function () {
        $.validate({
            validateOnBlur: false,
            showHelpOnFocus: false,
            onError: function () {
                alert('Validation failed');
            },
            onSuccess: function () {
                $(".form-submmit-button").click(function () {
                    var name = $(this).parents(".horizontal-form").find(".name");
                    var phone = $(this).parents(".horizontal-form").find(".phone");
                    var email = $(this).parents(".horizontal-form").find(".email");

                    alert('name: ' + name.val() + '\n phone: ' + phone.val() + '\n email: ' + email.val())
                    $.ajax({
                        type: 'POST',
                        url: 'ajax/form.php',
                        data: {
                            'name': name.val(),
                            'phone': phone.val(),
                            'email': email.val()
                        },
                        dataType: 'json',
                        success: $.proxy(function (data) {

                            if (data.error === false) {
                                $(this).next('.response').removeClass("error").addClass("success").html(data.response);
                                name - name.val('');
                                phone - phone.val('');
                                email - email.val('');
                            } else {
                                $(this).next().removeClass("success").addClass("error").html(data.response);
                            }

                            $(this).val("Установить трансляцию аудио");
                        }, this)
                    });
                });
                return false; // Will stop the submission of the form
            }
        });
    });

Everything works as wanted BUT ONLY Ajax sends a request to happen repeat button is pressed, and it is logical that vprintsii in this code . But if I bring news of the request without buttons as no longer work. Here is an example of code that does not work ...


  1. $(document).ready(function () {
        $.validate({
            validateOnBlur: false,
            showHelpOnFocus: false,
            onError: function () {
                alert('Validation failed');
            },
            onSuccess: function () {

                var name = $(this).parents(".horizontal-form").find(".name");
                var phone = $(this).parents(".horizontal-form").find(".phone");
                var email = $(this).parents(".horizontal-form").find(".email");

                alert('name: ' + name.val() + '\n phone: ' + phone.val() + '\n email: ' + email.val())
                $.ajax({
                    type: 'POST',
                    url: 'ajax/form.php',
                    data: {
                        'name': name.val(),
                        'phone': phone.val(),
                        'email': email.val()
                    },
                    dataType: 'json',
                    success: $.proxy(function (data) {

                        if (data.error === false) {
                            $(this).next('.response').removeClass("error").addClass("success").html(data.response);
                            name - name.val('');
                            phone - phone.val('');
                            email - email.val('');
                        } else {
                            $(this).next().removeClass("success").addClass("error").html(data.response);
                        }

                        $(this).val("Установить трансляцию аудио");
                    }, this)
                });
                return false; // Will stop the submission of the form
            }
        });
    });

What is the error and how to finish ? Thank you very much beforehand .