im使用google recaptcha为laravel 5的默认内置登录名,并且im在从API捕获验证码的验证响应的过程中(例如,成功:true | false)。以下是我用于与Google Recaptcha API通信的脚本。
//trigger the login button
$("#loginbutton").click(function (e) {
/* Check if the captcha is complete */
var captchaResponse = $("#g-recaptcha-response").val();
if ($("#g-recaptcha-response").val()) {
$.post("https://www.google.com/recaptcha/api/siteverify?secret=MySecretKeyHere&response=" + captchaResponse, {/* no data */}, function(response){
if(response.success)
{
alert("asdasd");
}
}, 'json');
} else {
alert("Please fill the captcha!");
}
e.preventDefault();
});
但是很遗憾,它无法正常工作,但出现了此错误(请参阅下面的内容)
recaptcha__fil.js:163 XHR已完成加载:POST“ https://www.google.com/recaptcha/api2/reload?k=mySiteKey”。xj.send @ recaptcha__fil.js:163Uk @ recaptcha__fil.js:211f.wj @ recaptcha__fil.js:209f.ye @ recaptcha__fil.js:207f。 kb @ recaptcha__fil.js:207f.send @ recaptcha__fil.js:208Wk.send @ recaptcha__fil.js:212L @ recaptcha__fil.js:33Wk.send @ recaptcha__fil.js:212(匿名函数)@ recaptcha__fil.js:284(匿名函数)@ recaptcha__fil.js:193z.la @ VM12395:1(匿名函数)@ recaptcha__fil.js:193e.Ob.e.wd @ recaptcha__fil.js:36fd @ recaptcha__fil.js:40bd @ recaptcha__fil.js:40L.kj @ recaptcha__fil.js:39Ic @ recaptcha__fil.js:33recaptcha__fil.js:163 XHR已完成加载:POST“ https://www.google.com/recaptcha/api2/userverify?k=mySiteKey”。xj.send @ recaptcha__fil.js:163Uk @ recaptcha__fil.js:211f.wj @ recaptcha__fil.js:209f.ye @ recaptcha__fil.js:207f.kb @ recaptcha__fil.js:207f.send @ recaptcha__fil.js:208Wk.send @ recaptcha__fil.js:212L @ recaptcha__fil.js:33Wk.send @ recaptcha__fil.js:212(匿名函数)@ recaptcha__fil.js:286(匿名函数)@ recaptcha__fil.js:193z.la @ VM12474:1(匿名函数)@ recaptcha__fil.js:193e.Ob.e.wd @ recaptcha__fil.js:36fd @ recaptcha__fil.js:40bd @ recaptcha__fil.js:40L.kj @ recaptcha__fil。 js:39Ic @ recaptcha__fil.js:33jQuery-2.1.3.min.js:4个选项https://www.google.com/recaptcha/api/siteverify?secret=MySecretKey n.ajaxTransport.k.cors.a.crossDomain.send @ jQuery-2.1.3.min.js:4n.extend.ajax @ jQuery-2.1.3 .min.js:4n.each.n。(匿名函数)@ jQuery-2.1.3.min.js:4(匿名函数)@ login:53n.event.dispatch @ jQuery-2.1.3.min.js: 3n.event.add.r.handle @ jQuery-2.1.3.min.js:3login:1 XMLHttpRequest无法加载https://www.google.com/recaptcha/api/siteverify?secret=MySecretKey。所请求的资源上没有“ Access-Control-Allow-Origin”标头。因此,不允许访问源“ http://juliver.motgh.com”。响应的HTTP状态码为405。
有什么想法吗?线索?救命?建议?建议?
您不能用您的密钥来自CLIENT验证您的客户端答案。您只能从服务器端执行此操作。因此,请更改代码以转到您的服务器((WebAPI等。)],然后从此处进行POST到Google URI。它应该工作。否则,没有必要进行此检查-您正在共享密钥...
所请求的资源上没有'Access-Control-Allow-Origin'标头。
这意味着您尝试使用的API不允许从http://juliver.motgh.com访问。
要了解为什么请求以这种方式失败,请学习HTTP access control (CORS)。
[Bhavin Solanki的答案可能会帮助您真正解决问题,您的后端不会在您的请求上放置访问控制。