检查表单preventing表单提交 [英] Validate Form preventing form submission

查看:170
本文介绍了检查表单preventing表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用asp.net MVC 5,并试图在提交验证表单。一切工作正常,直到我说下面一行code。使用Ajax调用验证表单。

I am using asp.net MVC 5 and trying to validate form on submission. everything works fine until i added the below line of code to validate form using ajax call.

    $('#signupform').validate({
    submitHandler: function (form) {            
        $.ajax({
            type: 'POST',
            data: JSON.stringify({ type: "WhatsNew", code: $('#PrimaryCode').val() }),
            url: '@Url.Action("CheckCode", "Home")',
            dataType: 'json',
            contentType: 'application/json'
        })
        .done(function (response) {
            if (response == 'success') {

                alert('success');
            }
            else {
                alert('failed');
            }
        });
        return false; // required to block normal submit since you used ajax
    }
});

以上code简单地阻止提交表单。

the above code simply blocking the submission of form.

推荐答案

可能的穿行:

这篇关于检查表单preventing表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆