title: how to check data return from php page to ajax success function
body: <p>I want to check the success function data using if loop in <code>ajax</code> below is the code any one help me.</p>
  
  <p>If the echo part return the success alert will come this the issue for me.</p>
  
  <p>Below is the <code>javascript</code> part and <code>php</code> part</p>
  
  <pre><code>    $(document).ready(function() {
              $("#newuserBtn").on("click", function() {
                  $("#regform").show();
                  $("#loginform").hide();
              });
  
              $("#submitBtn").on("click", function() {
                  var uid = $("#uid").val();
                  var pin = $("#inputPassword").val();
                  $.ajax({
                      type: "POST",
                      url: "validation.php",
                      data: {
                          uname: uid,
                          pwd: pin
                      },
                      success: function(value) {
                          if (value == "success") { //problem here 
                              alert();
                          }
                      }
                  });
  
              });
  
  // php code
  
  
  &lt;?php
  $servername = "localhost";
  $username   = "root";
  $password   = "ipad7*";
  $db_name    = "users";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $db_name);
  
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  //Gets username value from the URL
  $uname = $_POST['uname'];
  $pwd   = $_POST['pwd'];
  
  //Checks if the username is available or not
  $query  = "SELECT pin FROM users_details WHERE uid = '$uname'";
  $result = mysqli_query($conn, $query);
  
  if (mysqli_num_rows($result) &gt; 0) {
      // output data of each row
      while ($row = mysqli_fetch_assoc($result)) {
          if ($row["pin"] == $pwd) {
              echo "success";
          } else {
              echo "login fail";
          }
          //echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "&lt;br&gt;";
      }
  } else {
      //echo "login fail";
  }
  $conn-&gt;close();
  
  //echo "fff";
  //echo "$result";
  
  
  ?&gt;
  </code></pre>