From MSDN, HttpStatusCode.OK
is defined as follows (emphasis mine):
Equivalent to HTTP status 200. OK indicates that the request succeeded and that the requested information is in the response. This is the most common status code to receive.
Because a 200 implies some content is sent with the response (even an empty JSON object literal would be fine), you can run into problems if jQuery's Ajax implementation assumes a non-zero length response but does not receive it, especially if it tries parsing JSON (and possibly XML) from it. This is why John S makes the suggestion of changing the dataType
to text
; doing so would allow you to take specific action when receving an empty response.
On the other hand, HttpStatusCode.NoContent
is defined as (emphasis mine):
Equivalent to HTTP status 204. NoContent indicates that the request has been successfully processed and that the response is intentionally blank.
In your particular situation, it may make more sense to set the status code to HttpStatusCode.NoContent
to ensure that jQuery Ajax understands that it does not need to attempt any parsing/processing of the response.