0

我正在使用 XDomainRequest 发送跨域请求。onerror 处理程序正在触发;但是,没有记录任何内容,并且在开发人员工具中跟踪网络时,我可以在响应正文中看到响应。

有人有想法么?下面是我正在使用的代码。提前感谢您的帮助。

var createCORSRequest = function(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
  // Most browsers.
  xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
  // IE8 & IE9
  xhr = new XDomainRequest();
  xhr.open(method, url);
} else {
  // CORS not supported.
  xhr = null;
}
return xhr;
};

var url = 'https://myurl';

var method = 'GET';
var xhr = createCORSRequest(method, url);

xhr.onload = function() {
  // Success code goes here.
  //alert("load");
alert(xhr.responseText);
};

xhr.onprogress = function(){
 alert("Progress");     
}

xhr.onerror = function() {

  alert("error");
};


xhr.send();
4

1 回答 1

0

XDomainRequest 对象不提供任何方式来确定错误的状态码是什么,并在 xdr.responseText 中返回空字符串。

于 2014-12-05T05:20:02.727 回答