Javascript – XMLHttpRequest status 0 (responseText is empty)


Cannot get data with XMLHttpRequest (status 0 and responseText is empty):

xmlhttp=new XMLHttpRequest();"GET","", true);
    alert("status " + xmlhttp.status);

It alerts "status 0".

The same situation with the localhost request (cd_catalog.xml is saved as a local file)"GET","http://localhost/cd_catalog.xml", true);

But with the localhost IP request"GET","", true);

and with the local file request"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.

Best Solution

status is 0 when your html file containing the script is opened in the browser via the file scheme. Make sure to place the files in your server (apache or tomcat whatever) and then open it via http protocol in the browser. (i.e. http://localhost/myfile.html) This is the solution.

Related Question