admin管理员组文章数量:1406217
I am using Google reCaptcha v3. i am trying to implement it onto my aspx page.When i first load my page i can get a token back. However when i click on a button to process my page it es back with a "No reCaptcha clients exits". I did do a google search for this and nothing has came up to solve my issue. How can i verify a human or bot interaction?
this is what i have on my aspx page:
<div id="RegistrationForm">
<input type="text" id="FirstName" runat="server" value="" valtype="required" maxlength="150" />
<input type="text" id="LastName" runat="server" value="" valtype="required" maxlength="150" />
<input runat="server" id="Email" type="text" value="" valtype="required;regex:email" maxlength="350"/>
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"/> <br />
<div class="g-recaptcha" data-sitekey="SiteKey" data-callback="submit"></div>
<input id="btnProcessOrder" type="button" name="ProcessOrder" onclick="confirmed = false;capt();" value="Save" />
</div>
this is What i tried
<script src=".js?render=SiteKey"></script>
<script type="text/javascript">
//so when i load the page it gets my token and i can assign the value to g-recaptcha-response
grecaptcha.ready(function() {
grecaptcha.execute('SiteKey', { action: 'homepage' }).then(function (token) {
console.log(token);
document.getElementById('g-recaptcha-response').value = token;
});
});
Then when i try to verify the response as follows i get the error or it just does nothing:
function capt() {
var response = grecaptcha.getResponse();
$.ajax({
type: "POST",
url: '',
data: {"secret" : "SecretKey", "response" : response, "remoteip":"localhost"},
contentType: 'application/x-www-form-urlencoded',
success: function(data) { console.log(data); }
});// i call this function on my button
}
</script>
Most of the code i found is for php and i can not use that.How do i get this to work correctly?. Your response is highly appreciated
I am using Google reCaptcha v3. i am trying to implement it onto my aspx page.When i first load my page i can get a token back. However when i click on a button to process my page it es back with a "No reCaptcha clients exits". I did do a google search for this and nothing has came up to solve my issue. How can i verify a human or bot interaction?
this is what i have on my aspx page:
<div id="RegistrationForm">
<input type="text" id="FirstName" runat="server" value="" valtype="required" maxlength="150" />
<input type="text" id="LastName" runat="server" value="" valtype="required" maxlength="150" />
<input runat="server" id="Email" type="text" value="" valtype="required;regex:email" maxlength="350"/>
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"/> <br />
<div class="g-recaptcha" data-sitekey="SiteKey" data-callback="submit"></div>
<input id="btnProcessOrder" type="button" name="ProcessOrder" onclick="confirmed = false;capt();" value="Save" />
</div>
this is What i tried
<script src="https://www.google./recaptcha/api.js?render=SiteKey"></script>
<script type="text/javascript">
//so when i load the page it gets my token and i can assign the value to g-recaptcha-response
grecaptcha.ready(function() {
grecaptcha.execute('SiteKey', { action: 'homepage' }).then(function (token) {
console.log(token);
document.getElementById('g-recaptcha-response').value = token;
});
});
Then when i try to verify the response as follows i get the error or it just does nothing:
function capt() {
var response = grecaptcha.getResponse();
$.ajax({
type: "POST",
url: 'https://www.google./recaptcha/api/siteverify',
data: {"secret" : "SecretKey", "response" : response, "remoteip":"localhost"},
contentType: 'application/x-www-form-urlencoded',
success: function(data) { console.log(data); }
});// i call this function on my button
}
</script>
Most of the code i found is for php and i can not use that.How do i get this to work correctly?. Your response is highly appreciated
Share Improve this question edited Jun 20, 2019 at 14:42 marry asked Jun 20, 2019 at 14:34 marrymarry 1732 gold badges4 silver badges16 bronze badges 8-
Console
grecaptcha.getResponse();
and let us know what you get? – Brian Nezhad Commented Jun 20, 2019 at 14:51 - 1 @Farhad it says "ƒ (M,v){if(v=(M=void 0===M?pU():M,window.___grecaptcha_cfg.clients)[M],!v)throw Error("Invalid reCAPTCHA client id: "+ M);return da(v.id).value}" but i am using the exact same site key that they gave – marry Commented Jun 20, 2019 at 15:01
-
1
grecaptcha.getResponse();
is returning back a function. See what happens when you callresponse()
; What is yourconsole.log(data);
outputting? – Brian Nezhad Commented Jun 20, 2019 at 15:04 - It doesn't even reach that console, it just breaks at grecaptcha.getResonse() – marry Commented Jun 20, 2019 at 16:35
-
Are you sure you are including
/recaptcha/api.js
correctly?, Also can you confirm if you have set upgrecaptcha.render
? if yes, you can have a callback parameter, exampleverifyCallBack
and then right function forverifyCallBack
– Brian Nezhad Commented Jun 20, 2019 at 17:52
2 Answers
Reset to default 1According to the above ments:
You create a render function as following
grecaptcha.render('example3', {
'sitekey' : 'your_site_key',
'callback' : verifyCallback,
});
Then to get the response from the captcha you create a variable which will store the data as such:
var verifyCallBack = function(response) {
console.log(response);
};
Here we already have a same type of question : How to implement reCaptcha V3 in ASP.NET Please check these answers .
Also you can check this demo project for reference .https://github./NIHAR-SARKAR/GoogleRecaptchav3-example-In-asp
本文标签: javascriptHow to get a google recaptcha V3 responseStack Overflow
版权声明:本文标题:javascript - How to get a google recaptcha V3 response - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744987026a2636152.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论