.ajaxform not working inside the validation submitHandler?

前端 未结 1 1724
情深已故
情深已故 2021-01-16 06:05

i use the jquery validation plugin to validate form before submit in submitHandler i use ajax request to post the form with ajax before i used .ajax to send the request but

相关标签:
1条回答
  • 2021-01-16 06:32

    Try to invert the functions:

    jQuery('#form_id').ajaxForm({
        beforeSubmit: function() {
            jQuery("#form_id").validate({
                rules: {
                    first_name: "required",
                    last_name: "required"
                },
                messages: {
                    first_name: "Required",
                    last_name: "Required"
                }
            });
            return jQuery('#form_id').valid();
        },
        success: function(resp) {
            jQuery('#resp').html(resp).fadeIn('fast');
        }
    });
    

    Where #resp is the ID that will receive the HTML generated from the file your #form_id posted

    0 讨论(0)
提交回复
热议问题