【问题标题】:recaptcha: difficulty with the verifyrecaptcha:验证困难
【发布时间】:2013-04-10 22:07:12
【问题描述】:

我正在尝试实现 recaptcha。 我正在使用 jquery (ajax) 调用验证脚本 (http://www.google.com/recaptcha/api/verify)。 这将数据类型限制为 JSONP,google 拒绝所有其他数据类型。

问题是谷歌验证返回字符串如下: 真的 成功

或 错误的 '错误信息'

这会导致 jquery 端出现解析错误... 有没有人知道如何解决这种情况或最坏的情况,即使出现解析错误,也可以检索响应文本?

以下是我的 ajax 请求。我添加了用于测试的完整和错误功能。

$("#verifyCaptcha").click(function(){
    var chal = Recaptcha.get_challenge();
    var resp =  Recaptcha.get_response();                   
    $.ajax({
        url: "http://www.google.com/recaptcha/api/verify",  
        type: "GET",
        data: {
            privatekey: "MyKey",
            remoteip:  "172.29.129.133", 
            challenge:  chal,
            response: resp                          
        },
        //dataType: 'jsonp',
        success: function(output){  
            output = output.split('/n');
            console.log(output[0] + '**' + output[1]);
            if(output[0].toLowerCase() == 'true')
                $("#recaptcha_result").html('Succes: form will be sent.');
            else
                $("#recaptcha_result").html('Failed: form will NOT be sent.');
        },
        complete:function (xhr, status) {
            if (status === 'error' || !xhr.responseText) 
                console.log('an error occured');
            else 
                var data = xhr.responseText;
        },
        error: function(request, status, error)
        {
         if(request.responseText == 'success')
          $("#recaptcha_result").html('Succes: form will be sent.');
         else
          $("#recaptcha_result").html('Failed: form will NOT be sent.');       
          console.log(request.responseText + '**'+status + "**"+error);       
        }
    });                     

});

【问题讨论】:

    标签: jquery ajax captcha recaptcha


    【解决方案1】:

    我认为是因为请求的类型,它的AJAX和跨域请求是无效的。

    点击这里了解更多信息:

    Verifying RECAPTCHA with jQuery

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多