Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#5156 closed enhancement (duplicate)

Empty JSON response

Reported by: Rantanen Owned by:
Priority: major Milestone: 1.4
Component: ajax Version: 1.3.2
Keywords: json datatype Cc:
Blocked by: Blocking:


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.

Change History (2)

comment:1 Changed 12 years ago by addyosmani

Keywords: datatype added
Resolution: duplicate
Status: newclosed

comment:2 Changed 12 years ago by addyosmani

Duplicate of #6106.

Note: See TracTickets for help on using tickets.