Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获得google recaptcha V3响应_Javascript_Performance_Captcha_Recaptcha V3 - Fatal编程技术网

Javascript 如何获得google recaptcha V3响应

Javascript 如何获得google recaptcha V3响应,javascript,performance,captcha,recaptcha-v3,Javascript,Performance,Captcha,Recaptcha V3,我正在使用Google reCaptcha v3。我试图在我的aspx页面上实现它。当我第一次加载我的页面时,我可以拿回一个令牌。然而,当我点击一个按钮来处理我的页面时,它返回一个“No-reCaptcha clients exits”。 我确实在谷歌上搜索过这个问题,但没有找到任何解决我问题的方法。如何验证人机交互 这是我在我的aspx页面上的内容: <div id="RegistrationForm"> <input type="text" id="FirstName"

我正在使用Google reCaptcha v3。我试图在我的aspx页面上实现它。当我第一次加载我的页面时,我可以拿回一个令牌。然而,当我点击一个按钮来处理我的页面时,它返回一个“No-reCaptcha clients exits”。 我确实在谷歌上搜索过这个问题,但没有找到任何解决我问题的方法。如何验证人机交互

这是我在我的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>

//因此,当我加载页面时,它将获得我的令牌,我可以将该值分配给g-recaptcha-response
grecaptcha.ready(函数(){
执行('SiteKey',{action:'homepage'})。然后(函数(令牌){
console.log(令牌);
document.getElementById('g-recaptcha-response')。value=token;
});
});
然后,当我尝试按如下方式验证响应时,我得到了错误,或者它什么也不做:
函数capt(){
var response=grecaptcha.getResponse();
$.ajax({
类型:“POST”,
网址:'https://www.google.com/recaptcha/api/siteverify', 
数据:{“secret”:“SecretKey”,“response”:response,“remoteip”:“localhost”},
contentType:'application/x-www-form-urlencoded',
成功:函数(数据){console.log(数据);}
});//我在按钮上调用此函数
}
我找到的大部分代码都是针对php的,我不能使用它。我如何才能让它正常工作?。
根据以上评论,非常感谢您的回复

创建一个渲染函数,如下所示

grecaptcha.render('example3', {
    'sitekey' : 'your_site_key',
    'callback' : verifyCallback,
});
然后,为了从验证码中获得响应,您创建了一个变量,该变量将存储数据:

var verifyCallBack = function(response) { 
    console.log(response); 
};

这里我们已经有了一个相同类型的问题: 请检查这些答案


您还可以查看此演示项目以供参考。

Console
grecaptcha.getResponse()并让我们知道你得到了什么?@Farhad上面写着“如果(v=(M=void 0==M?pU():M,window.\uuuu grecaptcha\u cfg.clients)[M],!v)抛出错误(“无效的reCAPTCHA客户端id:+M);返回da(v.id).value}”,但我使用的是他们给出的完全相同的站点密钥
grecaptcha.getResponse()正在返回一个函数。查看调用
response()
时发生的情况;什么是您的
console.log(数据)输出?它甚至没有到达那个控制台,只是在grecaptcha.getResonse()处中断。你确定你正确地包含了
/recaptcha/api.js
,你还可以确认你是否设置了
grecaptcha.render
?如果是,您可以有一个回调参数,例如
verifyCallBack
,然后是
verifyCallBack
的右函数,它表示站点所有者错误:grecaptcha.rendor方法上的密钥类型无效。这真的没有任何意义,如果是他们给我的网站密钥,我甚至删除并创建了一个新的key@marry请确保您没有对该密钥进行限制,或者对于v2或v3版本的recaptcha,该密钥是否正确。我也推荐阅读,保养得很好。