【问题标题】:CaptchaMvc with ajaxCaptchaMvc 与 ajax
【发布时间】:2019-01-31 15:29:54
【问题描述】:

我正在使用 mvc4 c# 并使用 CaptchaMvc 中的表单查看。

我通过 ajax 发送表单数据:

$.ajax({
            url: $('#registerForm').attr("action"),
            type: 'POST',
            contentType: 'application/json',
            dataType: 'json',
            data: JSON.stringify($('#registerForm').serialize()),
            beforeSend: function () {

            },
            success: function (result) {
                //debugger;


            },
            error: function (event, request, settings) {
                //debugger;

            }
        });

我可以在萤火虫上看到“CaptchaInputText”发送到服务器,但我仍然收到错误

[NullReferenceException: 对象引用未设置为 对象。]
CaptchaMvc.Infrastructure.DefaultCaptchaManager.ValidateCaptcha(ControllerBase 控制器,IParameterContainer 参数容器)在 g:\CodePlex\Captcha\CaptchaMvc(Mvc 3)\Infrastructure\DefaultCaptchaManager.cs:435

如果我有这条线,它就会发生:

[CaptchaMvc.Attributes.CaptchaVerify("Captcha is not valid")] 

关于控制器动作, 如果不是,则没有错误,但验证码未得到验证。 怎么办?

【问题讨论】:

    标签: ajax asp.net-mvc-4 captcha


    【解决方案1】:

    尝试像这样更改您的请求:

    $.post($('#registerForm').attr("action"), $('#registerForm').serialize(),
            function(data) {
    
            }
        );
    

    我已经更新了示例并添加了一个带有ajax请求的示例,您可以下载它here

    【讨论】:

      猜你喜欢
      • 2015-05-01
      • 1970-01-01
      • 2015-07-30
      • 2011-11-23
      • 2012-06-05
      • 2013-05-25
      • 2011-06-14
      • 2020-04-06
      • 2014-03-18
      相关资源
      最近更新 更多