Backbone.NativeAjax icon indicating copy to clipboard operation
Backbone.NativeAjax copied to clipboard

Parse JSON based on accept header instead of content-type

Open PhilippMi opened this issue 9 years ago • 1 comments

Why does NativeAjax parse the response based on the provided accept header and only uses content-type if no custom accept header was specified?

If I provide an accept header like application/vnd.myformat, application/json;q=0.9 and the server is unable to serve application/vnc.myformat it will fall back to application/json. However, when the response is processed by NativeAjax, it only looks at the accept header and not on the response content type and therefore never parses JSON responses for this accept header.

Furthermore, the code only checks if the accept header starts with application/json, so if I rearrange my custom header to application/json;q=0.9, application/vnd.myformat it would parse the response. AFAIK the order of the MIME types is not relevant for the accept header according to the specification but NativeAjax depends on it.

PhilippMi avatar Jul 13 '15 13:07 PhilippMi

Sorry just saw this. I'll happily take a pull if you've got one. We could also look at the options.dataType argument passed in instead of parsing the response.

akre54 avatar Mar 14 '16 22:03 akre54