Bug Tracker

Ticket #5156 (closed enhancement: duplicate)

Opened 5 years ago

Last modified 3 years ago

Empty JSON response

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

Description

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

comment:1 Changed 4 years ago by addyosmani

  • Keywords datatype added
  • Status changed from new to closed
  • Resolution set to duplicate

comment:2 Changed 4 years ago by addyosmani

Duplicate of #6106.

Note: See TracTickets for help on using tickets.