rest - jQuery 2.0 + ASP.NET WebApi POST empty response = fail -
i'm using asp.net webapi build rest services. in many cases, need return 200 ok message (with no body). response typically looks (it's post):
return this.request.createresponse(httpstatuscode.ok);
or
return new httpresponsemessage(httpstatuscode.ok);
both worked in jquery 1.8, that's because version allowed responsetext of "" used (which attempts run parsejson on).
however, in jquery 2.0, ends in deferred.fail() callback instead, believes failed parsejson (on empty text) invalid..
how solve this?
update
example js call uses this:
var deferred = $.ajax({ "type": "post", "url": something, "contenttype": "application/json; charset=utf-8", "datatype": "json", "data": json.stringify(whatever) }); deferred.fail(function (msg) { // ends in here });
the call result in json response, needs return 200 ok no body, why i'm still specifying datatype/contenttype (there's no way know beforehand if have body or not, server has logic decide that).
your datatype
set json
means expect json server.
you try changing text
see if resolves issue.
or if it's not empty, try leaving out entirely jquery in theory should able recognize format.
see docs:
Comments
Post a Comment