title: Ajax return status 200 but error callback executed: how to catch message from server for encoding to json?
body: <p>My ajax request return status 200, but error callback is executed. This happens because command in php returns a message that is not json. For example, this happens when php try to unlink file without permissions (see code below). 
  If the message was encoded to json, success callback was executed in ajax. I'd like to manage this message in success callback.
  How to catch this message of no permissions for encoding to json, and prevent error callback is executed? </p>
  
  <p>Here is the code.</p>
  
  <p>siviglia.php</p>
  
  <pre><code>if ($_POST['action'] == 'cadice')
  {
      $this-&gt;barcellona.php($_POST['filename']);
  }
  
  public function barcellona($filename)
  {
      $u = unlink($filename);
      return $u;
  }
  </code></pre>
  
  <p>madrid.js</p>
  
  <pre><code>$.ajax({
          url: 'siviglia.php',
          type: 'POST',
          dataType: 'json',
          data: {
              action: 'cadice',
              filename: 'fn',
          },
          success: function(response){
              alert("success");
              }
          },
          error: function (xhr) {
              console.log(xhr.responseText);
          }
      });
  </code></pre>
  
  <p>If unlink return true, success callback is executed.
  If "No permissions" message is thrown from linux, it is returned in browser console as <code>xhr.responseText</code> and status is 200. How to catch it in success callback?</p>