Ticket #5156 (closed enhancement: duplicate)
Empty JSON response
|Reported by:||Rantanen||Owned by:|
jQuery gives a 'parsererror' when using the jQuery.ajax method with 'json' as datatype and the response is empty.
Ajax endpoints that "may or may not" return data are not that far fetched. An example would be a web service to a transactional data model where undoing a transaction returns the previous resource representation which might be null if there is no previous representation. While empty string is not valid JSON, I believe this should result in a succesful ajax call with null or undefined data (neither of which has valid JSON representation). It is cleaner to distinguish null from a valid object in the success handler than to delegate the "parsererror" resulting from an empty string from the error handler to the success handler so I don't believe allowing empty JSON should cause that much troubles.
The empty responses can be worked around by using a dataFilter that converts "" to "null", but it would be nice if this was built in.
#4326 might be related to this.