Jquery 仅限Ajax和google recaptcha V3

Jquery 仅限Ajax和google recaptcha V3,jquery,ajax,recaptcha,Jquery,Ajax,Recaptcha,我想使用Jquery和ajax提交数据,并做一些工作 正在尝试GoogleRecaptchaV3。在以下代码中,在行上显示警报(“令牌2是”+Mytoken);-->这里我得到一个错误,说Mytoken没有定义 问题是如何让grecaptcha.execute返回我可以在其他地方使用的数据?例如,如果验证码有效,那么我将使用令牌代码提交一些ajax数据,并在提交的后端脚本上验证令牌 <html> <head> <title&g

我想使用Jquery和ajax提交数据,并做一些工作

正在尝试GoogleRecaptchaV3。在以下代码中,在行上显示警报(“令牌2是”+Mytoken);-->这里我得到一个错误,说Mytoken没有定义

问题是如何让grecaptcha.execute返回我可以在其他地方使用的数据?例如,如果验证码有效,那么我将使用令牌代码提交一些ajax数据,并在提交的后端脚本上验证令牌

<html>
        <head>
            <title>Recaptcha Ajax</title>
            <script src="https://www.google.com/recaptcha/api.js?render=<?php echo $captcha_site_key; ?>"></script>
        </head>
        <body>



          <script>
          var MYtoken;
          grecaptcha.ready(function() {
              grecaptcha.execute('<?php echo $captcha_site_key; ?>', {action: 'test_page'}).then(function(token) {
                //$("#pet_token").val(token);
                //$('myform').prepend('<input type="hidden" name="recaptchaTOKEN" value="' + token + '">'); 


                alert ("token is " + token);
                alert ("and Mytoken is " + token);
              });
          });
        for (var i = 1; i <= 5; i++) {
            var tick = function(i) {
                return function() {
                    console.log(i);
                }
            };
            setTimeout(tick(i), 1000 * i);
        }
                alert ("token 2 is " + Mytoken);
          </script>

雷帕查阿贾克斯

我想出来了。。。不管我是否用Ajax提交一些数据,重要的是接收到的数据用重新验证码进行验证

所以。。。ajax只需在一个隐藏字段中设置值,在后端页面上,我进行验证码验证