title: Redirecting after JQuery AJAX request from PHP
body: <p>So when the login button is clicked, I use JQuery POST method to get data from login.php if the login was successful or not. If it wasn't (no user found), then it correctly displays the message.</p>
  
  <p>But when I want to redirect the user (user exists), it prints out the whole webpage into that one DIV.</p>
  
  <p>The JQuery after button is pressed:</p>
  
  <pre><code>$(function(){
  
  $("#login-form").submit(function() {
      event.preventDefault();
  
      var name = $('#inputName').val();
      var password = $('#inputPassword').val();
  
      $.post("login.php", 
      {
          name: name,
          password: password
      },
      function(data)
      {
          $("#resultDiv").hide().html(data).fadeIn(1000).effect( "shake", {direction:"up",times:2, distance:10}, 750 );
      });
  });
  });
  </code></pre>
  
  <p>If login not successful, it displays. But when I want to redirect, doesen't work:</p>
  
  <pre><code>if(!$row) {
  echo '&lt;div class="alert alert-danger" style="margin-top:25px; margin-bottom: 0px; text-align:center;"&gt;Invalid &lt;strong&gt;username&lt;/strong&gt; or &lt;strong&gt;password&lt;/strong&gt;.&lt;/div&gt;';
  } else {
  
    $line = mysqli_fetch_assoc($query);
  
    $_SESSION['IP'] = $line["IP"];
    $_SESSION['ID'] = $line["ID"];
    $_SESSION['username'] = $username;
  
    header("location:choose.php");
  }
  </code></pre>
  
  <p>So when the user logs in, how do I just redirect him? Don't want to display anything.</p>