Javascript cross-domain web request fails with Status=0?

Posted by Tav on Stack Overflow See other posts from Stack Overflow or by Tav
Published on 2010-04-26T01:32:53Z Indexed on 2010/04/26 1:43 UTC
Read the original article Hit count: 334

Filed under:
|

Yes, I know the following code does not work in IE. I know IE expects me to use XDomainRequest() instead. I don't care about that. This is firefox only.

I'm trying to do a cross-domain web request in firefox javascript. I keep getting a status of 0. Does anyone know why?

var url = "http://newyork.craigslist.org";
var xdr = new XMLHttpRequest(); //Yes, I know IE expects XDomainRequest. Don't care
xdr.onreadystatechange = function() { 
  if (xdr.readyState == 4) {
      alert(xdr.status); //Always returns 0! And xdr.responseText is blank too
  }
}
xdr.open("get", url, true);
xdr.send(null);

Shouldn't that work?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about cross-domain