title: AJAX request before regular form is being submitted
body: <p>I have a jQuery form validation script that is executed while user is trying to submit. I would like another function with AJaX request to be executed (and completed) after the form is validated but before it is sent. </p>
  
  <p>Here is the script. The <em>zglosip</em> function works okay when called separately; i.e. not from inside the <code>submit()</code> function.</p>
  
  <p><strong>zglosip(); (function that I want to be called)</strong></p>
  
  <pre><code>function zglosip() {
          $.ajax({
              type : 'post',
              url : 'res/php/nZglos.php',
              data : {
              "erepid" : "111",
              "ip" : "222",
              "poz" : "333"
              },
              success : function(data, textStatus, jqXHR) {
              tempor.html(data);
              },
              error : function(XMLHttpRequest, textStatus, errorThrown) {
              tempor.html(errorThrown);
              },
              dataType : 'text'
              return true;
          });
      };
  </code></pre>
  
  <p>validation script (created by <strong>Joren Rapini</strong> and modified by me)</p>
  
  <p>pole &amp; tempor are variables containing names of some divs</p>
  
  <pre><code>$("#forml").submit(function(){  
      //Validate required fields
      if ((pole.val() == "") || (pole.val() == blad)) {
          pole.addClass("podkresl");
          pole.val(blad);
      } else {
          pole.removeClass("podkresl");
      }
      // Validate the e-mail.
      if (!/\b(https?|ftp|file):\/\/[\-A-Za-z0-9+&amp;@#\/%?=~_|!:,.;]*[\-A-Za-z0-9+&amp;@#\/%=~_|]/.test(pole.val())) {
          pole.addClass("podkresl");
          pole.val(blad);
      }
  
  
      if ($(":input").hasClass("podkresl")) {
          return false;
      } else {
        if (zglosip() == true) {
            return true
        }
      }
  });
  </code></pre>
  
  <p>As you have already found out, I had tried to return true of the <code>submit()</code> function after the <code>zglosIp()</code> returned true (the if statement at bottom of the script). This did not work unfortunately, I have also tried calling <code>zglosip()</code> with separate <code>function{return true}</code> in it but surely I have not used it properly.
  Please help me.</p>