title: Return PHP error handling with AJAX
body: <p>I have a page powered with PHP and AJAX, when a user submits one of my forms I check for errors in the getData.php script.</p>
  
  <p>This example is if the user submits the form with the default value I'm wondering if there is a way to pass back those errors or trigger the AJAX to fire an error if the user commits on or if I need to do error handling before the AJAX call</p>
  
  <pre><code>$('form').on('submit', function (e) {
      e.preventDefault();
      $.ajax({
          type: 'post',
          url: '_ajax/addData.php',
          data: $('form').serialize(),
          success: function () {
              $("input").val('Info Here');
              $("form").hide();
              reloadInfo();
          }
      });
  });
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>$info = $_POST['info'];
  
  if($info != 'Info Here') {
      $conn = mysqli_connect();
      $query = "INSERT INTO leads VALUES(0, '$companyName', 1, NOW(), 3)";
      $result = mysqli_query($conn, $query) or die ('Error Could Not Query');
  
      $id = mysqli_insert_id($result);
      header("Location: http://localhost/manage/info.php?id=$id");
  
      mysqli_close($conn);
  } else { 
      echo '&lt;script&gt;alert("Error");/script&gt;'
  }
  </code></pre>
  
  <p><strong>PART 2</strong></p>