我尝试在我的一个表单中实现reCAPTCHA,...但我使用ajax作为提交.(更具体地说是原型ajax.updater)
一旦我提交并错误检查我的表单,我尝试加载reCAPCHTA小部件(在我更新的div元素中),它基本上只调用一个javascript文件,如下所示:
但是JS文件没有被读取?...我已经尝试了evalScripts的所有组合:true和evalJS:'force'等在ajax.updater .....但是我不认为我有一个非常好理解为什么js文件没有处理:(
如果有人能对这个问题有所了解,我将非常感激.
谢谢,安德鲁
这并没有解决你的确切问题,但是" 纸箱的黑暗面 "有一些优秀的代码可以通过jQuery AJAX来验证reCAPTCHA,这可能有所帮助.
综上所述:
添加以下Javascript:
$(function() { function validateCaptcha() { var challengeField = $('input#recaptcha_challenge_field').val(), responseField = $('input#recaptcha_response_field').val(); // alert(challengeField); // alert(responseField); // return false; var html = $.ajax({ type: 'POST', url: 'ajax.recaptcha.php', data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField, async: false }).responseText; if (html.replace(/^\s+|\s+$/, '') == "success") { $('#captchaStatus').html(' '); // Uncomment the following line in your application return true; } else { $('#captchaStatus').html( 'Your captcha is incorrect. Please try again' ); Recaptcha.reload(); return false; } } // Modified as per comments in site to handle event unobtrusively $('#signup').submit(function() { return validateCaptcha(); }); });
然后添加ajax.recaptcha.php文件,其中:"如果验证码匹配则只输出单词"success",如果失败则输出来自reCaptchta的响应.这很重要因为我们在validateCaptcha中寻找成功一词( )功能."
require_once('/inc/recaptchalib.php'); $publickey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // you got this from the signup page $privatekey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; $resp = recaptcha_check_answer( $privatekey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] ); if ($resp->is_valid) { ?>success< ? } else { die( "The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")" ); }
这个例子是在PHP中,但我很容易使用Zope/Python