JQuery ajax call receives invalid JSON, but no error handlers are called -


informational question rather issue need solved. couldn't find satisfactory answers elsewhere

i'm new jquery/js, , i'm trying test error handlers have ajax call rails backend. had hell of time getting handlers fire.

  1. i tried letting backend return 500 , stack trace, handlers didn't fire. console shows vm26658:1 uncaught syntaxerror: unexpected token s in json @ position 0.
  2. i tried returning empty response bad request status, same error , behavior
  3. i got handlers fire returning empty (but formed) json response , 400 status

so seems ajax error handlers don't fire when response body cannot parsed. correct? if seems pretty substantial , unintuitive limitation of handler logic. if not, how being stupid?

thanks!

update code

in haml:

= simple_form_for @object, method: :put, url: setup_object_path, remote: true |f| = f.input :some_input = f.submit, class: 'js-submit' 

in coffeescript:

$(document).on 'ajaxstart', startfunction $(document).on 'ajaxerror', errorfunction $(document).on 'ajaxcomplete', completefunction 

result: startfunction fires 3 cases, errorfunction , completefunction fire case #3

i tried binding directly js-submit ajax:error, had same result

found issue. in codebase had document level binding ajax:error used $.parsejson. wasn't valid json blowing , stopping other error handling.

sorry confusion , help


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo