reCAPTCHA with AJAX / jQuery

The following piece of jQuery will be executed once user clicks submit, but it doesn't reload reCAPTCHA, and I hope it does. The javascript code to reload reCAPTCHA is "Recaptcha.reload ()", can someone add it into my jQuery code?

Thanks.
ChiehkaiAsked:
Who is Participating?
 
Steve KrileConnect With a Mentor Commented:
Couldn't you add your reCaptcha text directly after the last function(data) pieces of your.post() success function?

                        function(data){
                                document.getElementById('message').innerHTML = data;

                                $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
                                $('#contactform #submit').attr('disabled','');
                                Recaptcha.reload ();   //<-ADD HERE
                               
                        }
0
 
ChiehkaiAuthor Commented:

jQuery(document).ready(function(){
        
        $('#contactform').submit(function(){
        
                var action = $(this).attr('action');
                
                
                $('#submit')
                        .after('<img src="images/ajax-loader.gif" class="loader" />')
                        .attr('disabled','disabled');
                
                $.post(action, { 
                        name: $('#name').val(),
                        email: $('#email').val(),
                        phone: $('#phone').val(),
                        subject: $('#subject').val(),
                        comments: $('#comments').val(),
                        recaptcha_challenge_field: $('#recaptcha_challenge_field').val(),
						recaptcha_response_field: $('#recaptcha_response_field').val()
                },
                        function(data){
                                document.getElementById('message').innerHTML = data;

                                $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
                                $('#contactform #submit').attr('disabled',''); 
                                
                        }
                );
                
                
                return false; 
        
        });
        
});

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.