Recaptcha with AJAX application, get new challenge using JavaScript

Currently, I am working on a commercial project (for me) that will be dedicated to the soul of Michael Jackson. I have used some AJAX based interface where I have used reCaptcha challenges to fight spamming. The form where I have used reCaptcha, will be submitted through AJAX calls. As the page won’t reload, the same captcha challenge exists even the user makes a mistake during filling the form.  I wanted to show a new challenge each time he/she makes a mistake. I thought, I will be in trouble in this part! However, I have seen it is extremely easy to get a new challenge.

On the reCaptcha interface, you will see a reload icon which loads a new challenge when clicked. Hovering on it, I see it calls a javascript method. I put the same method in my script and it worked without any issue. So, if you want to reload  a new challenge, just call this from your script:


That’s it! It will reload a new challenge.

Not sure, how to use it with your AJAX calls? Let me show an example. I am showing jQuery based example.

$('form').submit(function () {
$.ajax ({
url: 'your URL',
data: $(this).serialize(),
success: function (html){
alert('Thanks for submitting the form. It was fine all the way.');
} else {
alert('Something must be wrong. Please fill again carefully.');
type: 'POST'