title: JQuery ajax call receives invalid JSON, but no error handlers are called
body: <p>Informational question rather than an issue I need solved.  Couldn't find satisfactory answers elsewhere</p>
  
  <p>I'm new to JQuery/JS, and I'm trying to test error handlers I have for an AJAX call to a rails backend.  I had a hell of a time getting the handlers to fire.</p>
  
  <ol>
  <li>I tried letting the backend return a 500 and a stack trace, but the handlers didn't fire.  The console shows <code>VM26658:1 Uncaught SyntaxError: Unexpected token S in JSON at position 0</code>.</li>
  <li>I tried returning an empty response with a bad request status, but same error and behavior</li>
  <li>I finally got the handlers to fire by returning an empty (but well formed) JSON response and a 400 status</li>
  </ol>
  
  <p>So it seems that the Ajax error handlers don't fire when the response body cannot be parsed.  Is that correct?  If so that seems like a pretty substantial and unintuitive limitation of the handler logic.  If not, then how was I being stupid?</p>
  
  <p>Thanks!</p>
  
  <p><strong>Update with code</strong></p>
  
  <p>In haml:</p>
  
  <pre><code>= simple_form_for @object, method: :put, url: setup_object_path, remote: true |f|
  = f.input :some_input
  = f.submit, class: 'js-submit'
  </code></pre>
  
  <p>In Coffeescript:</p>
  
  <pre><code>$(document).on 'ajaxStart', startFunction
  $(document).on 'ajaxError', errorFunction
  $(document).on 'ajaxComplete', completeFunction
  </code></pre>
  
  <p>Result:
  <code>startFunction</code> fires for all 3 cases, but <code>errorFunction</code> and <code>completeFunction</code> only fire for case #3</p>
  
  <p>I also tried binding directly to <code>js-submit</code> with <code>ajax:error</code>, but had the same result</p>