title: return status code and get message on client side or send error message directly to client side
body: <p>I'm responding to an AJAX request, but there is a app error. (data validation failed, for example). How to notice the user?</p>
  
  <p><strong>1. Return Status Code, then get message by JS</strong></p>
  
  <pre><code>$.ajax(options).done(function(response){
      if (response.status === 1){
          // no problem, do next action
      } else {
          alert (messages[response.status]);
      }
  });
  
  var messages = {
      '0': 'Server Error',
      '-1': 'Invalid Data',
      ...
  }
  </code></pre>
  
  <p><strong>2. Return Status Code, and a message:</strong></p>
  
  <pre><code>$.ajax(options).done(function(response){
      if (response.status === 1){
          // no problem, do next action
      } else {
          alert (response.message);
      }
  });
  </code></pre>
  
  <p>Which one is better? or, what's the best practice? Note that, we have a bilingual application.</p>
  
  <p>Personally, I think first is better. Because I have to at least define an error message in my JS file, for server error. (when AJAX request fails, jQuery <code>.fail()</code>) So if I have to do it once, it's better to collect all messages together in same place.</p>