Recaptcha在没有插件的情况下验证用户的答案

时间:2014-07-10 08:57:54

标签: jquery recaptcha

https://developers.google.com/recaptcha/docs/verify 请参考此网址。 在paremeters下我们有remoteip(必需)我怎么能找到这个。 我的代码如下。

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>

        <form action="" method="post">

            <!-- ... your form code here ... -->

            <script type="text/javascript"
                    src="http://www.google.com/recaptcha/api/challenge?k=6LcmovYSAAAAAAnc1ZVXOIVk4g2J-GLmpnPlRINW">
            </script>
            <noscript>
                <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LcmovYSAAAAAAnc1ZVXOIVk4g2J-GLmpnPlRINW"
                        height="300" width="500" frameborder="0"></iframe><br>
                                                                          <textarea name="recaptcha_challenge_field" rows="3" cols="40">
       </textarea>
                                                                          <input type="hidden" name="recaptcha_response_field"
                                                                                 value="manual_challenge">
            </noscript>
            <input type="button" id="btnSubmit"/>
            <input type="submit" id="Button1"/>
            <!-- ... more of your form code here ... -->

        </form>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script>
            $(document).ready(function () {
                $("#btnSubmit").on('click', onSubmitClick);
            });

            function onSubmitClick() {
                alert();
                var challengeVal = $("#recaptcha_challenge_field").val();
                var responseVal = $("#recaptcha_response_field").val();
                var data = {
                    privatekey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                    remoteip: "127.1.1.0",
                    challenge: challengeVal,
                    response: responseVal
                };
                console.log(data);
                alert();
                $.ajax({
                    url: "http://www.google.com/recaptcha/api/verify",
                    context: data
                }).done(function (data) {
                    alert(data);
                });
            }
        </script>
    </body>
</html>

现在出现此错误

XMLHttpRequest cannot load http://www.google.com/recaptcha/api/verify. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 

我的猜测与跨浏览器ajax请求问题有关。

0 个答案:

没有答案