MVC 4 $Ajax JSON Request returns status 0, statusText: "error" -
i trying update value on page every 5 seconds using jquery $.ajax, code used work fine, after deployment production server appears randomly failing. on pages work, , on others if fails error: status 0, statustext: "error".
can spot errors misnomers in code / markup?
i use call method every 5 seconds:
setinterval(function () { updatemessages(); }, 5000);
updatemessages looks this:
function updatemessages() { $.ajax({ beforesend: function () { }, complete: function () { }, type: "get", url: '@url.action("getunreadmessagesjson", "message", new { area = "" })', contenttype: "application/json; charset=utf-8", datatype: "json", success: function (result) { var newunreadmessages = result.unreadmsgcount; }, error: function (rsult) { console.log(rsult); } }); }
my server code (action) inside mvc controller looks this:
public actionresult getunreadmessagesjson() { int unreadmessages = 0; try { unreadmessages = messageservice.getunreadmessagecount(websecurity.currentuserid); } catch (exception) { throw; } return json(new { unreadmsgcount = unreadmessages //,unreadmessages = unreadmessages }, jsonrequestbehavior.allowget); }
when use fiddler2 analyse request on local machine see in response:
http/1.1 200 ok cache-control: private content-type: application/json; charset=utf-8 server: microsoft-iis/7.5 x-aspnetmvc-version: 4.0 x-aspnet-version: 4.0.30319 x-powered-by: asp.net date: wed, 31 jul 2013 17:38:50 gmt content-length: 20
{"unreadmsgcount":3}
which looks , expect, never see request when site live. fiddler2 never shows outgoing ajax request, google chrome's console shows:
object {readystate: 0, getresponseheader: function, getallresponseheaders: function, setrequestheader: function, overridemimetype: function…}
which has status:0 , statustext: "error" inside. nothing more.
how on earth go investigating issue if there nothing wrong code? has seen before?
edit
after testing issue several browsers including ie, firefox , safari appears issue limited google chrome. have submitted bug report here , update post response get.
thanks,
explicitly set text/json follows
return json(new { unreadmsgcount = unreadmessages //,unreadmessages = unreadmessages }, "text/json", jsonrequestbehavior.allowget);
Comments
Post a Comment