title: How to get php return value using javascript?
body: <p>I'm trying to create an ajax request. Here's my code :</p>
  
  <pre><code>function cek(){
          var username = $("#username").val();
          var password = $("#password").val();
  
          if (username == "" &amp;&amp; password == "") {
              alert("Username and password can't be empty!");
          }else {
              $.ajax({
                  url: "processLogin.php",
                  type: "POST",
                  data:{
                      username: $("#username").val(), password: $("#password").val()
                  },
                  success:function(e){
                      alert("e");
                  }
              });
          }
      }
  </code></pre>
  
  <p>And here is the php code :</p>
  
  <pre><code>$username = $_POST['username'];
  $password = $_POST['password'];
  
  $sql = "SELECT * FROM user WHERE nama='$username' AND password='$password'";
  $query = $db-&gt;query($sql)or die(mysqli_error($db));
  $result = $query-&gt;fetch_assoc();
  
  if ($query-&gt;num_rows == 0) {
      echo "Username not found!"; 
  }elseif ($password != $result['password']) {
      echo "Password incorrect!";
  }else{
      header('location:index.php');
  }
  </code></pre>
  
  <p>I want my program to show an alert based on the result of <code>if else</code>. But it doesn't show any alert. I've search on google, but I still can't make it work.<br>Literally I'm new on using <code>ajax</code>. I hope someone can help me. Thank you.</p>