AngularJS $http error function never called -


i have simple code :

$http.get("/api/test")     .success(function (data, status, headers, config) {         console.log(data);         return data;     }).error(function (data, status, headers, config) {         alert("error");         return status; }); 

it works fine, error function never called, when return 404 (not found) server... in case calls 'success' function status = 404...

is correct?

thanks

fiddler:

request  http://localhost:41234/api/test http/1.1 host: localhost:41234 connection: keep-alive accept: application/json, text/plain, */* x-requested-with: xmlhttprequest user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.22 (khtml, gecko)    chrome/25.0.1364.172 safari/537.22 referer: http://localhost:41234/ accept-encoding: gzip,deflate,sdch accept-language: pt-br,pt;q=0.8,en-us;q=0.6,en;q=0.4 accept-charset: iso-8859-1,utf-8;q=0.7,*;q=0.3 cookie: asp.net_sessionid=bd1b3rib5j4beub0xbuhb1hm; formsauthentication=xxxxx  response  http/1.1 404 not found cache-control: no-cache pragma: no-cache expires: -1 server: microsoft-iis/8.0 x-aspnet-version: 4.0.30319 x-sourcefiles: =?utf-8?b?rdpcugvzc29hxvy2fylkfwavxhcgcg==?= x-powered-by: asp.net content-length: 0 

the problem webserver, setting content-length 0 means valid value can see on http/1.1 specification.

also made example on jsfiddle showing error , success examples. see here.

the headers error example:

request:

get /error/ http/1.1 host: fiddle.jshell.net connection: keep-alive accept: application/json, text/plain, */* user-agent: mozilla/5.0 (macintosh; intel mac os x 10_8_3) applewebkit/537.31 (khtml,  gecko) chrome/26.0.1410.65 safari/537.31 dnt: 1 referer: http://fiddle.jshell.net/danielcsgomes/camc6/1/show/ accept-encoding: gzip,deflate,sdch accept-language: en-us,en;q=0.8 accept-charset: utf-8,*;q=0.5 cookie: csrftoken=4tnvnxc5v6bsq9yjckkhlgfjbz3cclqd` 

response:

http/1.1 404 not found server: nginx/0.8.54 date: fri, 12 apr 2013 00:38:07 gmt content-type: text/html; charset=utf-8 transfer-encoding: chunked connection: keep-alive vary: cookie content-encoding: gzip 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -