title: How to send response from PHP to Ajax?
body: <p>This JavaScript code uses POST method to send data from form to PHP where PHP checks in database if data is true. But I don't know how to send response from PHP back to JS that fetching was successful. Can someone explain?</p>
  
  <p><strong>JS:</strong></p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>$('#submit-btn').on('click', function() {
  
    var dataString = 'username=' + document.getElementById('username').value + '&amp;password=' + document.getElementById('password').value + '&amp;rememberMe=' + document.getElementById('rememberMe').value;
  
    $.ajax({
      type: "POST",
      url: "ajaxsubmit.php",
      data: dataString,
      cache: false,
      success: function(){
        //check if what response is   
      } 
    });
  </code></pre>
  
  <p><strong>ajaxsubmit.php:</strong></p>
  
  <pre><code>&lt;?php
  session_start();
  
  //connect
  
  $username =$_POST['username'];
  $password =$_POST['password'];  
  
  $sql = "SELECT * FROM user WHERE email ='$username' OR username ='$username' AND password = '$password'";
  $result = mysqli_query($conn, $sql);
  
  if(!$row = mysqli_fetch_assoc($result)){     
      //response error
  } else{
       //response success
  }
  
  ?&gt;
  </code></pre>