如何验证在客户端验证码谷歌? [英] How to validate google recaptcha on client side?

查看:202
本文介绍了如何验证在客户端验证码谷歌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经经过3次登录谷歌实施的验证码在登录面板显示

I have implemented google reCaptcha on a login panel showing after 3 unsuccessful login

不过,我想验证的reCAPTCHA上这里登录按钮的点击使用jQuery客户端滑盖是code

But I want to validate reCaptcha on a client slide using jQuery on clicking of login button here is the code

<div style="display:none;width:310px;top:205px;left:558px;position:absolute" id="grecaptcha" runat="server">
  <cc1:GoogleReCaptcha  ID="ctrlGoogleReCaptcha1"  runat="server" PublicKey="6LdHrQ0TAAAAAD77ubv9Jr6q4RYkyddhXzX-XPB3" PrivateKey="xxxxxxx" />

  </div>
  <span id="captcha" style="margin-left:588px;color:red" />
<asp:Button ID="LoginButton" runat="server" OnClientClick="get_action();" CommandName="Login" Text="Inloggen" ValidationGroup="Login1" />

我如何通过使用jQuery做呢?

How can I do this by using jQuery?

推荐答案

我分享我的code解决方案。但是的 proxy.php 的等细节与​​完整的解释,你可能会发现的此处

I share my code solution. But the proxy.php and other details with the full explanation you might find here.

<script src="https://www.google.com/recaptcha/api.js" >;
<form method="post">
<div class="g-recaptcha" data-sitekey="[site_key]" data-callback="onReturnCallback" data-theme="light"></div>
<input value="submit" type="submit" />
</form>

JS的验证

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
var onReturnCallback = function(response) { 
    //alert('g-recaptcha-response: ' + grecaptcha.getResponse()); 
    var url='proxy.php?url=' + 'https://www.google.com/recaptcha/api/siteverify';  
    $.ajax({ 'url' : url, 
               dataType: 'json',
               data: { response: response},
               success: function( data  ) {                     
                var res = data.success.toString();
                        alert( "User verified: " + res);                    
                if (res ==  'true') { 
                       document.getElementById('g-recaptcha').innerHTML = 'THE CAPTCHA WAS SUCCESSFULLY SOLVED'; 
                                } 
                           } // end of success: 
         }); // end of $.ajax 
}; // end of onReturnCallback 
</script>

这篇关于如何验证在客户端验证码谷歌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆