title: Asynchronous form submission with parsley.js
body: <p>I'm trying to create a form that is validated front end using Parsley.js and submitted asynchronously. The form is called #contactForm and the submit button is #sendData, the error comes when I hit submit on an empty or invalid form. I expect to see an 'Error' alert from invalid form data but instead it just continues with the Else condition and the data is processed by contactForm.php.</p>
  
  <hr>
  
  <pre><code>$(document).ready(function() { 
  
      // submit data on click and check if valid 
      $('#sendData').click(function(e) { 
          //check if valid with parsley
          var valid = $('#contactForm').parsley ( 'validate' );
          if ( valid === false )
          {
              e.preventDefault();
          }
          else 
          {
              $.post("contactForm.php", $("#contactForm").serialize());       
          }
      });
  }); 
  </code></pre>
  
  <hr>
  
  <p>Proper solution below.</p>