我正在使用 Google reCaptcha v3。我正在尝试在我的 aspx 页面上实现它。当我第一次加载我的页面时,我可以获得一个令牌。但是,当我单击一个按钮来处理我的页面时,它会返回“没有 reCaptcha 客户端退出”。我确实对此进行了谷歌搜索,但没有任何东西可以解决我的问题。如何验证人或机器人交互?
这是我在我的 aspx 页面上的内容:
<div id="RegistrationForm">
<input type="text" id="FirstName" runat="server" value="" valtype="required" maxlength="150" />
<input type="text" id="LastName" runat="server" value="" valtype="required" maxlength="150" />
<input runat="server" id="Email" type="text" value="" valtype="required;regex:email" maxlength="350"/>
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"/> <br />
<div class="g-recaptcha" data-sitekey="SiteKey" data-callback="submit"></div>
<input id="btnProcessOrder" type="button" name="ProcessOrder" onclick="confirmed = false;capt();" value="Save" />
</div>
这是我试过的
<script src="https://www.google.com/recaptcha/api.js?render=SiteKey"></script>
<script type="text/javascript">
//so when i load the page it gets my token and i can assign the value to g-recaptcha-response
grecaptcha.ready(function() {
grecaptcha.execute('SiteKey', { action: 'homepage' }).then(function (token) {
console.log(token);
document.getElementById('g-recaptcha-response').value = token;
});
});
Then when i try to verify the response as follows i get the error or it just does nothing:
function capt() {
var response = grecaptcha.getResponse();
$.ajax({
type: "POST",
url: 'https://www.google.com/recaptcha/api/siteverify',
data: {"secret" : "SecretKey", "response" : response, "remoteip":"localhost"},
contentType: 'application/x-www-form-urlencoded',
success: function(data) { console.log(data); }
});// i call this function on my button
}
</script>
我发现的大部分代码都是用于 php 的,我不能使用它。我怎样才能让它正常工作?非常感谢您的回复