每当我提交表单时,即使存在有效令牌,我为无效令牌设置的错误消息也会始终触发。<script src="https://www.google.com/recaptcha/api.js?render=SITE_KEY"></script><script>grecaptcha.ready(function () { grecaptcha.execute('SITE_KEY', { action: 'contact' }).then(function (token) { var recaptchaResponse = document.getElementById('recaptchaResponse'); recaptchaResponse.value = token; });});表单中的隐藏字段: <input type="hidden" name="recaptcha_response" id="recaptchaResponse">我正在序列化整个表格:var form = $('#supportForm').serialize();如果我 console.log 可以看到令牌,那么那里没问题。阿贾克斯: $.ajax({ url: 'validate.php', type: 'POST', dataType: 'json', data: form, //PHP$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';$recaptcha_secret = 'SECRET_KEY';$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $_POST['recaptcha_response']);$recaptcha = json_decode($recaptcha); if(!$recaptcha->success) { $message .= "'Robot verification passed, please try again"; }我不知道它是否失败,因为在我的 google 帐户中,我将域设置为 mydomain.com 但该表单实际上位于 mydomain.com/subdirectory设置验证码时我无法添加子目录。
- 1 回答
- 0 关注
- 197 浏览
添加回答
举报
0/150
提交
取消