开发者

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

开发者 https://www.devze.com 2022-12-28 07:49 出处:网络
EDIT: It\'s been pointed out below that this doesn\'t work because craigslist doesn\'t set an Allow-Cross-Domain header. OK, I\'ll buy that. Is there any other way to use javascript in firefox to down

EDIT: It's been pointed out below that this doesn't work because craigslist doesn't set an Allow-Cross-Domain header. OK, I'll buy that. Is there any other way to use javascript in firefox to download a page cross-domain then?


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?


Craigslist doesn't allow cross-domain requests to it. It needs to send a proper Access-Control-Allow-Origin header.

0

精彩评论

暂无评论...
验证码 换一张
取 消