jQuery $.when() .then() not working for me
<p>$.when() .then() is not working for me, what am I doing wrong? Thanks in advance for your help. I want to make sure the form is loaded first then I want to populate a <code>&lt;div&gt;</code> inside the form to show Google's recaptcha. This is the test: It actually loads the form but the alerts are not poping up at all. I the test works I'll change the "alerts" to call the showRecaptcha function. </p>

<pre><code>&lt;script type="text/javascript"&gt;
$("document").ready(function () {
    function showRecaptcha(element) {
           Recaptcha.create("publick_key_here", element, {
             theme: "red",
             callback: Recaptcha.focus_response_field});
   };

  // load the form
  $.get('../php/formularioDeReserva.html', function (data) {
    $.when($('.subscriptionForm').html(data))
       .then(function(){alert('Then')})
       .fail(function(){alert( 'failed.' )});
    alert('I reached this point.');
  });

})
&lt;/script&gt;
</code></pre>

<p>Note for <strong>Felix</strong>: My tests show that <code>.html(data)</code> is not done instantaneously. In the following code if I leave the <code>alert('Load was performed.')</code> the pause of the alert give some time so the <code>showRecaptcha</code> succeds. If I remove the alert nothing works.</p>

<pre><code>$.get('../php/formularioDeReserva.html', function (data) {
        $('.subscriptionForm').html(data);
         alert('Load was performed.');
         showRecaptcha('recaptcha_div');
        });
</code></pre>

<p>Note for <strong>Guiherme</strong>: Trying what you suggested, which seems to me a good logical idea, still does not work, and I don't understand why not. In the following code the <em>subcritionForm</em> shows but the <code>success</code>, <code>error</code> and <code>complete</code> alerts do not pop up at all.</p>

<pre><code>$.get('../php/formularioDeReserva.html', function (data) {
        $('.subscriptionForm').html(data);
         // alert('Load was performed.');
         // showRecaptcha('recaptcha_div');
    })
    .success(function() { alert("second success"); })
    .error(function() { alert("error"); })
    .complete(function() { alert("complete"); });
</code></pre>

<p>Note: When did a "view source" I realized that the Java script was included twice because one of the file was not saving properly. That explained why the alerts were popping twice.</p>
