[英]Google Recaptcha V2 response error
I am trying to implement Google Recaptcha V2 using Server side code implementation.Now when i am trying to send g-recaptcha-response
i am getting an error like ReferenceError: g is not defineddata: JSON.stringify(g-recaptcha-response),
and when i am not sending this parameter i am getting Not defined error
on server side code.Here is my Client side Code using AJAX.. 我正在尝试使用服务器端代码实现来实现Google Recaptcha V2。现在,当我尝试发送
g-recaptcha-response
时,出现了类似ReferenceError: g is not defineddata: JSON.stringify(g-recaptcha-response),
的错误ReferenceError: g is not defineddata: JSON.stringify(g-recaptcha-response),
当我不发送此参数时,服务器端代码上出现Not defined error
。这是我使用AJAX的客户端代码。
$(document).ready(function () {
$('#Captcha').click(function () {
$.ajax({
type: 'POST',
url: 'http://localhost:64132/ValidateCaptcha',
data: JSON.stringify(g-recaptcha-response),
contentType: "application/json; charset=utf-8",
dataType: 'json', // Set response datatype as JSON
success: function (data) {
console.log(data);
if (data = true) {
$("#lblmsg").text("Validation Success!!");
} else {
$("#lblmsg").text("Oops!! Validation Failed!! Please Try Again");
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error");
}
});
});
});
Please help me to resolve and implement the same. 请帮助我解决并实施相同的程序。
See the docs how to verify g-recaptcha-responce
. 请参阅文档,如何验证
g-recaptcha-responce
。 Actually it's text-area field, so in jquery you might address it as $('#g-recaptcha-response').val() 实际上,它是文本区域字段,因此在jquery中,您可以将其寻址为$('#g-recaptcha-response')。val()
So on client side: 因此在客户端:
var response = $('#g-recaptcha-response').val();
$.ajax({
type: 'POST',
url: 'http://localhost:64132/ValidateCaptcha',
dataType: 'json',
data: { response: response },
...
Seems to me that you do a tricky thing: Immediate on reCaptcha click you make a xhr (jquery ajax request): 在我看来,您做了一件棘手的事情:在reCaptcha上单击立即,您发出一个xhr(jquery ajax请求):
$('#Captcha').click(function () { $.ajax({...})
Yet, google api might has not yet evaluated the bot-human cues and has not returned response. 但是,谷歌api可能尚未评估机器人的提示,也没有返回响应。 Therefore no
g-recaptcha-response
is present on a client side when you invoke xhr! 因此,在调用xhr时,客户端上不存在
g-recaptcha-response
。
Better you wait (timeout) untill $('#g-recaptcha-response').val() <> ''
and then you make xhr to veryfy site. 更好的是,您等待(超时)直到
$('#g-recaptcha-response').val() <> ''
,然后将xhr转到非常方便的站点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.