reCAPTCHA Ajax API + custom theme not working

2020-07-08 07:30发布

问题:

I can't see where I'm going wrong. I've tried everything I could think of, reCAPTCHA is just not working with the Ajax API. Here's what my code looks like:

<!-- this is in <head> -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://api.recaptcha.net/js/recaptcha_ajax.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    Recaptcha.create("my key here", "recaptcha_widget", {
        "theme": "custom",
        "lang": "en",
        "callback": function() { console.log("callback"); } // this doesn't get called
    });
});
</script>
<!-- ... this is in <body> -->
<div id="recaptcha_widget" style="display: none">
    <div id="recaptcha_image"></div>
    <div id="recaptcha_links">
        <a href="javascript:Recaptcha.reload()">get another</a> &bull;
        <a class="recaptcha_only_if_image" href="javascript:Recaptcha.switch_type('audio')">switch to audio</a>
        <a class="recaptcha_only_if_audio" href="javascript:Recaptcha.switch_type('image')">switch to image</a> &bull;
        <a href="javascript:Recaptcha.showhelp()">help</a>
    </div>
    <dt>Type the words</dt>
    <dd><input type="text" id="recaptcha_response_field" name="recaptcha_response_field"></dd>
</div>

回答1:

Works for me? What is happening? What are you trying to do?

When I substitute and alert for the console.log it alters everytime the page loads or a new reCaptcha gets generated. Exactly like it is supposed to.

The callback is not where you submit it for validation, if that is what you are trying to do then look here: http://recaptcha.net/apidocs/captcha/



回答2:

Sorry for answering my question again. Found the problem, apparently you can't use reCAPTCHA in locally stored files (accessed via file:///), they have to be on a http:// site. As soon as I put this on localhost it worked.

+1 durilai for letting me know it works with him/her, this way I was able to look at the problem from a different perspective.