问题描述
我想在注册表单中使用 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 (将#修改为@)