title: How to trigger jquery.ajax() error callback based on server response, not HTTP 500?
body: <p>By using jquery ajax function, I can do something like:</p>
  
  <pre><code>$.ajax({
  
    url: url,
    type: 'GET',
    async: true,
    dataType: 'json',
    data: data,
  
   success: function(data) {
  
       //Handle server response here
  
    },
  
   error: function(xhr, status, error){
  
      //Handle failure here
  
   }
  
  });
  </code></pre>
  
  <p>I got two questions to ask based on above code:</p>
  
  <ol>
  <li><p>When will the jquery.ajax() <code>error</code> callback be called??</p></li>
  <li><p>What if server response to me a json object with string message "<em>There is an error</em>". Which means the request is still send successfully, but I got server response <code>{message: "There is an error"}</code>. </p></li>
  </ol>
  
  <p>I think no matter what string value server is responsed, if client got server's response, the <strong>jquery.ajax()</strong> <code>success</code> callback will be triggered anyway.</p>
  
  <p>I'd like to ask if server specifically returns to me a JSON object with string value like <code>{message: 'There is an error'}</code>, could server do something so that this response could be handled in <strong>jquery.ajax()</strong> <code>error</code> callback instead of <code>success</code> callback?</p>