ReCaptcha 3 HTML Helper 在按钮中单击 ASP.NET MVC

问题描述

我想在注册表单中使用 re-captcha 3,我想点击按钮检查 re-captcha。

我用这个article

我在注册按钮中有这个代码

$("#Register").click(function() {
   var $this = $(this);
   if ($(".ThemeContainer input[type='radio']:checked").length == 0 || !$("form").valid()) {
     return false;
   }
   if (!$("#@Html.IdFor(m => m.Confirm)").is(":checked")) {
     return false;
   }
  if ($("form").valid()) {
   $.ajax({
    url: '@Url.Action("Register","Account")',data: $("form").serialize(),type: 'POST',success: function(data) {
    if (data.IsSuccess) {
    window.location.href = data.Url;
    } else {
    $("#FinalMessage").html(data.Message);
    }
   },error: function() {
     }
   });
        }
         return false;
    });

如何在其中使用grecaptcha.execute

public static IHtmlString ReCaptchaJS(this HtmlHelper helper,string useCase = "homepage")  
{  
    string reCaptchaSiteKey = GoogleReCaptchaVariables.ReCaptchaSiteKey;  
    string reCaptchaApiScript = "<script src='https://www.google.com/recaptcha/api.js?render=" + reCaptchaSiteKey + "'></script>;";  
    string reCaptchaTokenResponseScript = "<script>$('form').submit(function(e) { e.preventDefault(); grecaptcha.ready(function() { grecaptcha.execute('" + reCaptchaSiteKey + "',{action: '" + useCase + "'}).then(function(token) { $('#" + GoogleReCaptchaVariables.InputName + "').val(token); $('form').unbind('submit').submit(); }); }); }); </script>;";  
    return MvcHtmlString.Create($"{reCaptchaApiScript}{reCaptchaTokenResponseScript}");  
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...