title: jQuery ajax second post
body: <p>When I hit the submit button at the first time these codes works. But when I hit the second time to the button even if email and password values were true nothing happens and the user can not login. But if I write the true values at the first time, it works and user can login. So I figured the cause of this problem is about the "return false;" phrase. But if I remove return false; phrase, the form posts and ajax codes become useless. I must avoid the posting without ajax.
  jQuery:</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function(){
      $('#submit-btn').click(function(){
          var email = $('#email').val();
          email = $.trim(email);
          var password = $('#password').val();
          password = $.trim(password);
  
              if(email == "") {
                  $('#email').css({
                      "background-color": "#FF7070"
                  });
                  $('#box1').css({
                          "visibility": "visible"
                  });
                  return false;
              }else if(password == "") {
                  $('#password').css({
                      "background-color": "#FF7070"
                  });
                  $('#box2').css({
                          "visibility": "visible"
                      });             
                  return false;
              }else{
  
                    $.ajax({
                      type: "POST",
                      url: "ajax.php",
                      data: $('#loginform').serialize(),
                      timeout: 5000,
                      success: function(c) {
                          if(c == "no") {
                              $('#box3').css({
                                  "visibility": "visible"
                              });
                              return false;
                          } else if (c == "ok") {
                              window.location.href = "homepage.php";
                          }
                      },
                      error: function(a, b) {
                          if (b == "timeout") {
                              alert("Error: #101");
                          }
                      },
                      statusCode: {
                          404: function(){
                              alert("Error: #102")
                          }
                      }
                    });
              }
             return false;
      })
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Html:</p>
  
  <pre><code>&lt;form name="loginform" id="loginform" method="post" action=""&gt;
              &lt;div class="field"&gt;
                  &lt;input type="text" maxlength="40" id="email" name="email" placeholder="E-mail"&gt;
              &lt;/div&gt;
  
              &lt;div class="field"&gt;
                  &lt;input type="password" id="password" name="password" placeholder="Password" autocomplete="off"&gt;
              &lt;/div&gt;
  
              &lt;div class="field"&gt;
                  &lt;input type="submit" id="submit-btn" value="Log in"&gt;
              &lt;/div&gt;
  
              &lt;div class="keep-login"&gt;
                  &lt;label for="remember"&gt;
                      &lt;input type="checkbox" name="remember" id="remember" checked="checked"&gt;Remember me
                  &lt;/label&gt;
                  &lt;span&gt;&lt;a href="#"&gt;Forgot password?&lt;/a&gt;&lt;/span&gt;
              &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>PHP: </p>
  
  <pre><code>if(Input::exists()) {
      if(Token::check(Input::get('token'))) {
  
          $validate = new Validate();
          $validation = $validate-&gt;check($_POST, array(
              'email' =&gt; array('required' =&gt; true),
              'password' =&gt; array('required' =&gt; true)
          ));
  
          if($validation-&gt;passed()) {
              $user = new User();
  
              $remember = (Input::get('remember') === 'on') ? true : false;
              $login = $user-&gt;login(Input::get('email'), Input::get('password'), $remember);
  
              if($login) {
                  echo "ok";
              } else {
                  echo "no";
              }
  
          } else {
              echo "no";       
          }
      }
  }
  </code></pre>