我想使用服务器端code implementation.Now当我尝试发送实现谷歌的reCAPTCHA V2 G-验证码响应
我收到一个错误如的ReferenceError:g不defineddata:JSON.stringify(G-验证码响应),
,当我不发送这个参数我收到不在服务器端code.Here定义的错误
是使用AJAX我的客户端code ..
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..
$(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.
请参见文档如何验证 G-验证码-的反响
。其实它的文本区域字段,所以在jQuery的你可以解决它为$('#G-验证码响应)。VAL()
See the docs how to verify g-recaptcha-responce
. Actually it's text-area field, so in jquery you might address it as $('#g-recaptcha-response').val()
所以,在客户端:
var response = $('#g-recaptcha-response').val();
$.ajax({
type: 'POST',
url: 'http://localhost:64132/ValidateCaptcha',
dataType: 'json',
data: { response: response },
...
请参阅我的帖子上吧。
在我看来,你做一件棘手的事情: 立即对验证码点击你犯了一个XHR(jQuery的Ajax请求):
Seems to me that you do a tricky thing: Immediate on reCaptcha click you make a xhr (jquery ajax request):
$('#验证码)。点击(函数(){
$阿贾克斯({...})
$('#Captcha').click(function () {
$.ajax({...})
然而,谷歌API的威力还未评估的僵尸人线索,并没有返回的响应。因此,没有 G-验证码响应
是present上的客户端,当你调用XHR!
Yet, google api might has not yet evaluated the bot-human cues and has not returned response. Therefore no g-recaptcha-response
is present on a client side when you invoke xhr!
更好的等待时间(超时),直到 $('#G-验证码响应)VAL()<> ''
,然后你让XHR来veryfy网站。
Better you wait (timeout) untill $('#g-recaptcha-response').val() <> ''
and then you make xhr to veryfy site.