Unable to retrieve data with XMLHttpRequest (status 0 and responseText is empty):
xmlhttp = new XMLHttpRequest ();
xmlhttp.open ("GET", "http://www.w3schools.com/XML/cd_catalog.xml", true);
xmlhttp.onreadystatechange = function ()
{
if (xmlhttp.readyState == 4)
alert ("status" + xmlhttp.status);
}
xmlhttp.send ();
It alerts "status 0".
The same situation with the localhost request (cd_catalog.xml is saved as a local file)
xmlhttp.open ("GET", "http: //localhost/cd_catalog.xml", true);
But asking for localhost IP address
xmlhttp.open ("GET", "http://127.0.0.1/cd_catalog.xml", true);
and requesting a local file
xmlhttp.open ("GET", "cd_catalog.xml", true);
everything is in order (status 200)
What can cause the problem (status = 0) with an online request?
PS: Live HTTP Headers shows that everything is in order in all four cases:
HTTP / 1.1 200 OK
Content-Length: 4742
PS2: local Apache web server on VMWare (Win7 host system, Ubuntu guest OS, network adapter - NAT). Browser - Firefox.
arigasa Feb 15 2018-11-15T00: 00Z
source share