简体   繁体   English

使用Google Invisible Recaptcha的Ajax表单

[英]Ajax Form With Google Invisible Recaptcha

My code: 我的代码:

 function onSubmit(token) { $(document).ready(function() { $("#submit").click(function() { var name = $("#name").val(); var email = $("#email").val(); var password = $("#password").val(); var contact = $("#contact").val(); // Returns successful data submission message when the entered information is stored in database. var dataString = 'name1=' + name + '&email1=' + email + '&password1=' + password + '&contact1=' + contact; //AJAX code to submit form. $.ajax({ type: "POST", url: "ajaxsubmit.php", data: dataString, cache: false, success: function(result) { alert(result); } }); return false; }); }); $("#i-recaptcha").submit(); }; 
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="https://www.google.com/recaptcha/api.js" async defer></script> <form id='i-recaptcha'> <input type="text" id="name" /><br/> <input type="text" id="email" /><br/> <input type="password" id="password" /><br/> <input type="text" id="contact" /><br/> <br/> <input type="submit" id="submit" value="Submit" class="g-recaptcha" data-sitekey="6Lcjvi4UAAAAAIR7_ckItF2HfMEFHx427WUDdGDk" data-callback="onSubmit" /> </form> 

Problem: 问题:

When the user clicks on submit button for the first time, the captcha box appears, as expected. 当用户第一次单击“ submit按钮时,将按预期显示验证码框。

But after completing the captcha verification, the box closes, and the form do not get submitted. 但在完成验证码验证后,框会关闭,表单不会被提交。

The user needs to click on the submit button again, in order to submit the form. 用户需要再次单击submit按钮才能提交表单。

Expected result: 预期结果:

Click on submit button > Recaptcha box Appear > Verified > Automatically submit the form 单击提交按钮> Recaptcha框出现>已验证>自动提交表单

Original Result 原始结果

Click on submit button > Recaptcha box Appear > Verified > Click on submit button again > submit the form 点击提交按钮>回收箱出现>已验证>再次点击提交按钮>提交表格

I thought this line will submit the form after completing captcha 我认为这行将在完成验证码后提交表格

$( "#i-recaptcha" ).submit();

$("#submit").click(function() {

This function gets executed, when #submit button is clicked. 单击#submit按钮时,将执行此功能。 Change it to submit() , function. 将其更改为submit() ,function。

Here is the full code: 这是完整的代码:

 function onSubmit(token) { $(document).ready(function() { $("#i-recaptcha").submit(function() { var name = $("#name").val(); var email = $("#email").val(); var password = $("#password").val(); var contact = $("#contact").val(); // Returns successful data submission message when the entered information is stored in database. var dataString = 'name1=' + name + '&email1=' + email + '&password1=' + password + '&contact1=' + contact; //AJAX code to submit form. $.ajax({ type: "POST", url: "ajaxsubmit.php", data: dataString, cache: false, success: function(result) { alert(result); } }); return false; }); $("#i-recaptcha").submit(); }); }; 
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="https://www.google.com/recaptcha/api.js" async defer></script> <form id='i-recaptcha'> <input type="text" id="name" /><br/> <input type="text" id="email" /><br/> <input type="password" id="password" /><br/> <input type="text" id="contact" /><br/> <br/> <input type="submit" id="submit" value="Submit" class="g-recaptcha" data-sitekey="6Lcjvi4UAAAAAIR7_ckItF2HfMEFHx427WUDdGDk" data-callback="onSubmit" /> </form> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM