本文介绍了使用jQuery验证RECAPTCHA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery验证Recaptcha,但我一直收到错误告诉我:访问受限制的URI被拒绝代码:1012

I'm trying to verify a Recaptcha using jQuery, but I keep getting an error telling me: Access to restricted URI denied" code: "1012

这是我到目前为止所做的尝试:

This is what I've tried so far:

 var challengeVal = $("#recaptcha_challenge_field").attr("value");
 var reponseVal = $("#recaptcha_response_field").attr("value");
 var remoteIp = <%= "'" + Request.ServerVariables["REMOTE_HOST"] + "'" %>
 var privateKey = 'MY_PRIVATE_KEY';

 var requestUrl = "http://api-verify.recaptcha.net/verify?privatekey=" + privateKey + "&remoteip=" + remoteIp + "&challenge=" + challengeVal + "&response=" + reponseVal;

 $.ajax({
    type: "POST",
    url: requestUrl,
    dataType: "json",
    success: function(data) {
       alert('response from recaptcha');
    },
    error: function() {
       alert("An error occured.");
    }
  });

任何人都试过这个,谁可以指出我正确的方向?

Anyone tried this, who can point me in the right direction?

谢谢。

推荐答案

出于安全原因,禁止JavaScript制作跨域XMLHttpRequests。有,但它们只能用于你控制两个域。

JavaScript is prohibited from making cross-domain XMLHttpRequests for security reasons. There are workarounds, but they only work if you control both domains.

解决方案:对你自己的服务器进行AJAX调用,并通过服务器端代码联系recaptcha。

Solution: Make an AJAX-call to your own server, and contact recaptcha through server side code.

这篇关于使用jQuery验证RECAPTCHA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 01:49