title: jQuery - Resume form submit after ajax call
body: <p>Is it possible to stop a form from submitting and then resubmitting the same form from within the success of an ajax call?</p>
  
  <p>At the moment it gets to the success bit but it doesn't resubmit the form which should submit and redirect the user to the <a href="http://example.com" rel="nofollow noreferrer">http://example.com</a> website.</p>
  
  <p>Thank you very much for any help in advance</p>
  
  <p>If it's not possible to do it this way, is there another way of getting it to work?</p>
  
  <pre><code>$(document).ready(function() {
      $('form').submit(function(e) {
          e.preventDefault();
  
          $.ajax({
              url: $('form').attr('action'),
              type: 'post',
              data: $('form').serialize(),
              success: function(data) {
                  if (data == 'true')
                  {
                      $('form').attr('action', 'http://example.com');
                      $('form').unbind('submit').submit(); // mistake: changed $(this) to $('form') - Problem still persists though it does not resubmit and redirect to http://example.com
                  }
                  else
                  {
                      alert('Your username/password are incorrect');
                  }
              },
              error: function() {
                  alert('There has been an error, please alert us immediately');
              }
          });
      });
  });
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>Stackoverflow posts checked out for the code below:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/15185431/resume-form-submission-after-ajax-call">Resume form submission after $.ajax call</a></li>
  <li><a href="https://stackoverflow.com/questions/1164132/how-to-reenable-event-preventdefault">How to reenable event.preventDefault?</a></li>
  </ul>
  
  <p>I just thought I'd mention I have also tried this code without avail.</p>
  
  <pre><code>var ajaxSent = false;
  $(document).ready(function() {
      $('form').submit(function(e) {
  
          if ( !ajaxSent)
              e.preventDefault();
  
          $.ajax({
              url: $('form').attr('action'),
              type: 'post',
              data: $('form').serialize(),
              success: function(data) {
                  if (data == 'true')
                  {
                      alert('submit form');
                      ajaxSent = true;
                      $('form').attr('action', 'http://example.com');
                      $('form').submit();
                      return true;
                  }
                  else
                  {
                      alert('Your username/password are incorrect');
                      return false;
                  }
              },
              error: function() {
                  alert('There has been an error, please alert us immediately');
                  return false;
              }
          });
      });
  });
  </code></pre>
  
  <p>I have also tried this code without any luck as well.</p>
  
  <pre><code>$(document).ready(function() {
      $('form').submit(function(e) {
          e.preventDefault();
  
          $.ajax({
              url: $('form').attr('action'),
              type: 'post',
              data: $('form').serialize(),
              success: function(data) {
                  if (data == 'true')
                  {
                      $('form').attr('action', 'http://example.com');
                      $('form').unbind('submit').submit();
                      return true;
                  }
                  else
                  {
                      alert('Your username/password are incorrect');
                      return false;
                  }
              },
              error: function() {
                  alert('There has been an error, please alert us immediately');
                  return false;
              }
          });
      });
  });
  </code></pre>