我正在使用 google recaptcha在从 API 捕获验证码验证响应的过程中,默认内置了 laravel 5 和 im 的登录名(例如 success: 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 finished loading: 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(anonymous function) @ recaptcha__fil.js:284(anonymous function) @ recaptcha__fil.js:193z.la @ VM12395:1(anonymous function) @ 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:33 recaptcha__fil.js:163 XHR finished loading: 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(anonymous function) @ recaptcha__fil.js:286(anonymous function) @ recaptcha__fil.js:193z.la @ VM12474:1(anonymous function) @ 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:33 jQuery-2.1.3.min.js:4 OPTIONS 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.(anonymous function) @ jQuery-2.1.3.min.js:4(anonymous function) @ login:53n.event.dispatch @ jQuery-2.1.3.min.js:3n.event.add.r.handle @ jQuery-2.1.3.min.js:3 login:1 XMLHttpRequest cannot load https://www.google.com/recaptcha/api/siteverify?secret=MySecretKey. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://juliver.motgh.com' is therefore not allowed access. The response had HTTP status code 405.
有什么想法吗?线索?帮助?建议?有什么建议吗?
最佳答案
您无法使用来自客户端的 key 验证您的客户端答案。您必须仅从服务器端执行此操作。因此,请更改代码以转到您的服务器(WebAPI 等),然后从那里执行 POST 到 Google URI。它应该有效。否则进行此检查是没有意义的 - 您正在共享您的 key ...
关于javascript - 请求的资源上不存在 'Access-Control-Allow-Origin' header 。响应的 HTTP 状态代码为 405,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31579766/