Bug Tracker

Opened 7 years ago

Closed 7 years ago

#13350 closed bug (notabug)

jQuery ajax PUT call results in error when the server response is in JSON and empty string

Reported by: mpermana@… Owned by: mpermana@…
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc:
Blocked by: Blocking:

Description

jQuery ajax PUT call results in error when the server response is in JSON and empty string

  1. The version(s) of jQuery affected: 1.9.0 The previous version of jQuery works as can bee seen in the provided test case.
  2. The browser: chrome Version 24.0.1312.56, but browser doesn't matter
  3. The operating system: MacOS, does not need to do anything
  4. A description of what you expect to happen:

The following ajax call results in error, in previous version of jQuery, they don't result in error. It should not result in error because the HTTP response is 200.

[start reproduce code]

$.ajax({
    type: "PUT",
    url: 'https://taru.zeeses.com:8443/map/jquerybug.jsp',
    error: function() {
        alert('ERROR you should not see this, but you see this in 1.9.0');
    },
    success: function() {
        alert('SUCCESS this does not work in 1.9.0, but you see it works in 1.8.3 and bellow');
    }
});

[end reproduce code]

[begin jquerybug.jsp]

<%
response.setContentType("text/json");
%>

[end jquerybug.jsp]

Similar ticket, I think similar cause, but it is different case: http://bugs.jquery.com/ticket/13292

Reproducible test case is also saved in: http://jsfiddle.net/ceCqV/5/

Change History (4)

comment:1 Changed 7 years ago by dmethvin

Sounds like this case: http://jquery.com/upgrade-guide/1.9/#jquery-ajax-returning-a-json-result-of-an-empty-string

Can you confirm?

It should not result in error because the HTTP response is 200.

That is not the sole criteria of whether the success/error handler is called. If the data type is JSON, the JSON returned must be valid.

Since JSON.parse("") (an empty string) is an error, this change just aligns the AJAX processing with that result.

If you want a successful JSON result of null, return a response body with the four characters null.

comment:2 Changed 7 years ago by dmethvin

Owner: set to mpermana@…
Status: newpending

comment:3 Changed 7 years ago by mpermana@…

Status: pendingnew

Yes, that is exactly the case, since it's documented, let's close as not a bug.

comment:4 Changed 7 years ago by dmethvin

Resolution: notabug
Status: newclosed
Note: See TracTickets for help on using tickets.