我试图使用服务器端代码V2实现Google implementation.Now,当我试图发送g-recaptcha-response时,我得到了一个类似于ReferenceError: g is not defineddata: JSON.stringify(g-recaptcha-response),的错误,而当我没有发送这个参数时,我在服务器端得到了Not defined error,code.Here是我使用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");
}
});
});
});请帮助我解决和实施同样的问题。
发布于 2015-09-28 12:59:19
请参阅文档如何验证g-recaptcha-responce。实际上,它是文本区域字段,因此在jquery中,您可以将其命名为$(‘#g-’).val()
因此,在客户端:
var response = $('#g-recaptcha-response').val();
$.ajax({
type: 'POST',
url: 'http://localhost:64132/ValidateCaptcha',
dataType: 'json',
data: { response: response },
... 在上面看我的帖子。
再来点
在我看来,您似乎做了一件棘手的事情:立即单击reCaptcha,就可以发出xhr (jquery请求):
$('#Captcha').click(function () { $.ajax({...})
然而,google可能还没有评估bot-人工提示,也没有返回响应。因此,当您调用xhr时,客户端不存在g-recaptcha-response!
最好是等待(超时)直到$('#g-recaptcha-response').val() <> '',然后让xhr对站点进行验证。
https://stackoverflow.com/questions/32818430
复制相似问题