Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8319673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:24:02+00:00 2026-06-08T22:24:02+00:00

Live Examples: Without AJAX With AJAX (click Email Us link) When I view the

  • 0

Live Examples:

  • Without AJAX
  • With AJAX (click Email Us link)

When I view the source page everything works fine, but when I load through an AJAX request, in the place where the reCAPTCHA should be, I see…

<noscript>
  <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LfwkccSAAAAALr_z6vDBqkySowo5KIiR0mVM1BX" height="300" width="500" frameborder="0"></iframe><br/>
  <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
  <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>

Obviously, this does nothing unless my user has JS disabled. During this process no errors are thrown.

Viewing the code on the non-AJAX-requested pace, I see…

<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LfwkccSAAAAALr_z6vDBqkySowo5KIiR0mVM1BX"></script>

<noscript>
  <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LfwkccSAAAAALr_z6vDBqkySowo5KIiR0mVM1BX" height="300" width="500" frameborder="0"></iframe><br/>
  <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
  <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>

Note the additional line at the top of the script that addresses users with JS enabled.

So I guess the question is two-fold. WTF is happening and how can I fix it?

I’ve found some vague mention of this issue, but no decent answers. I found some mention of the reCAPTCHA API using document.write, but I don’t know if that’s valid. If I’ve overlooked something obvious, please feel free to point it out.

Per request, the AJAX call is…

$(document).ready(function() {
     $.get('/inc/email.php', 
           function(data){
                console.log('Get success!');
                $('#email-form').html(data);
                console.log('Get added to #email-form!');
                $('#email-form form').submit( function(){
                    $.ajax({
                      type: "POST",  
                      url: "/inc/email.php",  
                      data: $('#email-form form').serialize(),  
                      success: function() {
                            console.log('Submit success!');
                            $('#email-form').html(data);
                      }
                    });
                    return false;
                });
        }
     );
 });

What I’ve tries so far:

  • Rewriting the code to fetch the remote JS file, replace the document.write() clause with an append to the element I set to a specific ID, then run the modified code inline on the page
  • Displaying reCAPTCHA Without Plugins instead of the PHP reCAPTCHA library
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:24:03+00:00Added an answer on June 8, 2026 at 10:24 pm

    Explanation:

    The reason this breaks when doing it with AJAX, is because jQuery strips out any script tags from your HTML before appending it to the DOM, and evaluates it in the global context. It does not insert it into the DOM together with the rest of your HTML.


    In your code:

    The culprit in your code is this line:

    $('#email-form').html(data);
    

    You’re taking the raw HTML string recieved from the server, and appending it to the DOM. However, jQuery first removes the script tag from your data variable, and evaluate that in the global context.

    Since the recaptcha.js script uses document.write to add its stuff to the DOM, it breaks; document.write has to run exactly where you want it to output the HTML.


    Solutions:

    There are 2 possible solutions.

    Solution #1:

    Instead of relying on jQuery completely, you could insert the script tag yourself using vanilla JavaScript, which will cause the document.write to run where you want it to – right there in the DOM:

    success: function() {
        var form = $('#email-form')[0],
            script = $('<script src="http://www.google.com/recaptcha/api/challenge?k=6LfwkccSAAAAALr_z6vDBqkySowo5KIiR0mVM1BX" />')[0];
    
        form.appendChild(script);
    }
    

    Note the [0] at the end of those lines. They’re used to access the underlying native DOM object, so that we can use the DOM’s native appendChild.

    Solution #2:

    Instead of loading the data through AJAX, consider putting it in a page of its own, and then just insert an iframe into your page:

    success: function() {
        $('#email-form').html('<iframe src="path/to/reCAPTCHA/page.html" />');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read a book that systematically introduces dom with live examples. Any
Where to get live video + audio streaming examples ( GStreamer )? So for
Is $(*).click(function(){...}) considered expensive? - See here . How about sending an ajax request
I know this kind of thing cannot be adequately answered without a link to
Is it possible to get page description from page url without slowdowing the page
I'm working on a ajax/jquery quiz for my company and it runs without problem
Using the event click with live function leads to strange behavior when using Firefox*.
Is it possible to remove the hash from window.location without causing the page to
Here is a live example: http://jsfiddle.net/Pzvdv/ <ul id=navigation> <li><a href=#>HOME</a></li> <li><a href=#>OUR APPROACH</a></li> <li><a
Consider the following example: ( live demo here ) HTML: <div class=board> <div class=row>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.