Wednesday, April 4, 2018

javascript - XMLHttpRequest status 0 (responseText is empty)

Cannot get 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 with the localhost IP request




xmlhttp.open("GET","http://127.0.0.1/cd_catalog.xml", true);



and with the local file request




xmlhttp.open("GET","cd_catalog.xml", true);


everything is OK (status 200)




What can cause the problem (status=0) with the online request?



PS: Live HTTP Headers shows that everything is OK in all 4 cases:




HTTP/1.1 200 OK
Content-Length: 4742


PS2: Apache local web server on VMWare (host OS Win7, Guest OS Ubuntu, Network adapter – NAT). Browser – Firefox.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...