What does it mean when JavaScript network calls such as fetch or XMLHttpRequest, or any other type of HTTP network request, fail with an HTTP status code of 0?
This doesn't seem to be a valid HTTP status code as other codes are three digits in HTTP specification.
I tried unplugging the network completely as a test. It may be unrelated, but that resulted in status code 17003 (IIRC), which cursory searching suggests means "DNS server lookup failed".
The same code works fine from some locations and systems, however within certain environments it fails with status code 0 and there is no responseText provided.
This is a typical HTTP POST to an Internet URL. It does not involve file:// which I understand may return 0 indicating success in Firefox.
I found a new and undocumented reason for status == 0. Here is what I had:
It was not cross-origin, network, or due to cancelled requests (by code or by user navigation). Nothing in the developer console or network log.
I could find very little documentation on state() (Mozilla does not list it, W3C does) and none of it mentioned "rejected".
Turns out it was my ad blocker (uBlock Origin on Firefox).
For what it is worth, depending on the browser, jQuery-based AJAX calls will call your success callback with a HTTP status code of 0. We've found a status code of "0" usually means the user navigated to a different page before the AJAX call completed.
Not the same technology stack as you are using, but hopefully useful to somebody.
In my case the status became 0 when i would forget to put the WWW in front of my domain. Because all my ajax requests were hardcoded http:/WWW.mydomain.com and the webpage loaded would just be http://mydomain.com it became a security issue because its a different domain. I ended up doing a redirect in my .htaccess file to always put www in front.
wininet.dll
returns both standard and non-standard status codes that are listed below.For the status code "zero" are you trying to do a request on a local webpage running on a webserver or without a webserver?
XMLHttpRequest status = 0 and XMLHttpRequest statusText = unknown can help you if you are not running your script on a webserver.
I believe the error code indicates that the response was empty, (as not even headers were returned). This means the connection was accepted and then closed gracefully (TCP FIN). There are a number of things which could cause this, but based off of your description, some form of firewall seems the most likely culprit.
As detailed by this answer on this page, a status code of 0 means the request failed for some reason, and a javascript library interpreted the fail as a status code of 0.
To test this you can do either of the following:
1) Use this chrome extension, Requestly to redirect your url from the
https
version of your url to thehttp
version, as this will cause a mixed content security error, and ultimately generate a status code of 0. The advantage of this approach is that you don't have to change your app at all, and you can simply "rewrite" your url using this extension.2) Change the code of your app to optionally make your endpoint redirect to the
http
version of your url instead of thehttps
version (or vice versa). If you do this, the request will fail with status code 0.