title: Do not open page when try to make login using jquery, ajax and php
body: <p>I have the file "index.html" that contains login form, a file "dash.js" that gets username and password from login form and redirects to the file "connectdb.php" that check the login with database, and in case of success start a session in file "stock.php". The problem is that when I try to make login it redirects to the file "stock.php", but it sends again for index.html, do not showing the page "stock.php". The password and username are correct. I do not know what I'm doing wrong.
  Here is go my code.</p>
  
  <p>dash.js</p>
  
  <pre><code>$('#btnlogin').click(function() {
      var username = $('#user').val();
      var password = $('#pass').val();
      console.log("passsas qaqiioooo" + username + "- " + password);
      $.ajax({
          type: 'POST',
          url: 'connectdb.php',
          data: {user: username, pass: password},
          success: function(data){
                  window.location="stock.php";
          },
          error: function(jqXHR, textStatus, errorThrown){
              alert('deu barraca: ' + textStatus);
          }
      });
  });
  </code></pre>
  
  <p>connectdb.php</p>
  
  <pre><code>&lt;?php
  
  $server = 'localhost';
  $user = 'root';
  $password = '********';
  $database = '***********';
  
  $con = mysqli_connect($server, $user, $password, $database);
  
  if (!$con) {
    die('Nao e possivel conectar a base de dados: ' . mysqli_error($con));
  }
  
  
  if (isset($_POST['user']) &amp;&amp; isset($_POST['pass'])) {
        $myusername = $_POST['user'];
      $mypassword = $_POST['pass'];
      $myusername = stripslashes($myusername);
      $mypassword = stripslashes($mypassword);
      $myusername = mysql_real_escape_string($myusername);
      $mypassword = mysql_real_escape_string($mypassword);
      $sql="SELECT * FROM user WHERE username='$myusername' and password='$mypassword'";
      $result=mysqli_query($con,$sql);
  
      $count=mysqli_num_rows($result);
  
      // If result matched $myusername and $mypassword, table row must be 1 row
      if($count==1){
          $_SESSION['myusername'] = $myusername;
          $_SESSION['mypassword'] = $mypassword;
      }
      else {
          echo "Wrong Username or Password";
      }
  }
  ?&gt;
  </code></pre>
  
  <p>stock.php</p>
  
  <pre><code>&lt;?php
  session_start();
  if(!isset( $_SESSION['myusername'] )){
      header("location:index.html");
  }
  ?&gt;
  
  &lt;html&gt;
  &lt;body&gt;
  Login Successful
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Sorry for my bad english.</p>