title: AJAX Error Handling from PHP
body: <p>My current script only handles errors with a vague &amp; general error message when the execution fails but I'd like to have it return various error messages. Many of the other answers I find are similar to what I already have where I'm unable to do what I desire here.</p>
  
  <p><strong>Current AJAX (What I require changed)</strong>:</p>
  
  <pre><code>$.ajax(
  {
      url: './ajax.php',
      data: {value1: 'test', value2: 'test', isChecked: isChecked},
      dataType: 'json',
      success: this.exeSuccess,
      error: this.exeError
  });
  
  
  this.exeSuccess = function(){
      var currentRow = $(this).closest('tr');
      // Highlights table row to denote successful execution
      currentRow.toggleClass('colorcode');
  };
  
  this.exeError = function(){
      alert("Error. Please try again.");
      return false;
  };
  </code></pre>
  
  <p><strong>Current PHP:</strong></p>
  
  <pre><code>if (isset($_GET['value1']) &amp;&amp; isset($_GET['value2']) &amp;&amp; isset($_GET['isChecked'])) {
  
      // Execution logic here... if it fails, the whole script terminates
      echo json_encode("");
  }
  </code></pre>
  
  <p><strong>What I plan on doing with PHP to return detailed error messages to AJAX:</strong></p>
  
  <pre><code>if (isset($_GET['value1']) &amp;&amp; isset($_GET['value1']) &amp;&amp; isset($_GET['isChecked'])) {
  
      $errorMessage = "";
  
      if (isset($_GET['isChecked']) == 'false'){
          $errorMessage = "The check box is false";
      } else {
          $errorMessage = "The check box is true";
      }
  
      echo json_encode("$errorMessage");  // But how I handle it in the AJAX error:?
  }
  </code></pre>
  
  <p>How could I get the error messages handled in "AJAX error:" so that different <strong>alert([error_message]</strong>) can be executed?</p>