2

I'm looking a JavaScript code to reload google recaptcha after submit button without refreshing page.

Actually this following code is working, but once I click on submit button, it won't allow my form to submit, the recaptcha will be reset. I'm looking for a solution that after submit button, then recaptcha will be unchecked without effecting to my form. Because my form response is in the same page, that's why I want to reset recaptcha after form submitted.

$('form').submit(function(e){
grecaptcha.reset();     
});

I highly appreciate if you will help me on this.

James
  • 201
  • 1
  • 3
  • 9
  • You cannot use the handler on [.submit()](https://api.jquery.com/submit/) because that is called before it actually goes through. You will need to either use some form of `$.ajax` or the solution suggested [here](https://stackoverflow.com/a/18086670/3072752) – Namaskar Aug 17 '17 at 18:11
  • 1
    Thanks for your guide and help. I could solve it. thumbs up – James Aug 17 '17 at 19:46

1 Answers1

3

Special Thanks to user: Sven The Surfer

Here is my Solution:

$(document).ready(function() {
$("#form_captcha").submit(function() {
$.ajax({
type: "POST",
success: function() {
grecaptcha.reset();     
}})})})

Above Ajax need jquery.min.js version 3.2.1

James
  • 201
  • 1
  • 3
  • 9