title: ajax request after jquery validation
body: <p>I try to make an ajax request after a successful form validation. If I delete the <code>,</code> after <code>url: 'loginprivate.php'</code> the php code works but the validation dont. If I add the <code>,</code> the validation works but the php code not. The redirection after successful ajax request dont work anyway. How can I make that working, maybe with <code>$(form).ajaxSubmit();</code> when yes where should I add this line?</p>
  
  <pre><code> $(document).ready(function () {
          $('#myform').validate({ // initialize the plugin
              rules: {
                  username: {
                      required: true,
                      minlength: 2,
                      maxlength: 30
                  },
                  password: {
                      required: true,
                      minlength: 3,
                      maxlength: 30
                  }
              },
              submitHandler: function (form) { // for demo
                  $.ajax({
      type: 'post',
      url: 'loginprivate.php',   //url where you want to post the stuff.
      data:{
          username: 'root',
          password: ''
      },
      success: function(res){
          //here you will get res as response from php page, either logged in or some error.
           window.location.href = "http://localhost/localcorps/main.php";
      }
  });
                  return false; // for demo
              }
          });
      });
  </code></pre>
  
  <p><strong>my php code:</strong></p>
  
  <pre><code>    if(isset($_POST["submit"]))
      {
              $hostname='localhost';
              $username='root';
              $password='';
  
              unset($_POST['password']);
              $salt = ''; 
              for ($i = 0; $i &lt; 22; $i++) { 
                      $salt .= substr('./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', mt_rand(0, 63), 1); 
              }
              $_POST['password'] = crypt($_POST['password'],'$2a$10$'.$salt);
              $new = 0;
              try {
                      $dbh = new PDO("mysql:host=$hostname;dbname=search",$username,$password);
                      $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // &lt;== add this line
                      $sql = "INSERT INTO users (username, password)
                      VALUES ('".$_POST["username"]."','".$_POST["password"]."')";
                      if ($dbh-&gt;query($sql)) {
                              echo "New Record Inserted Successfully";
                      }
                      else{
                              echo "Data not successfully Inserted.";
                      }
                      $new = $dbh-&gt;lastInsertId();
                      $dbh = null;
              }
              catch(PDOException $e)
              {
                      echo $e-&gt;getMessage();
              }
              if ($new &gt; 0) 
              {
  
                  $t = time() + 60 * 60 * 24 * 1000;
                  setcookie("username", $_POST['username'], $t);
                  setcookie("userid", $new , $t);
              } 
          else
              {
  
              }
      }
  </code></pre>