【发布时间】:2018-04-04 21:00:44
【问题描述】:
在我的 Javascript 文件中,我想从该站点加载 xml 数据:https://www.anime2you.de/feed/
但尽管使用了 CORS,但我总是得到没有 Access-Control-Allow-Origin 标头。是我误解了 CORS 的概念/用法还是网站有问题?
我的代码:
var feeds = ["https://www.anime2you.de/feed/"];
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://www.anime2you.de/feed/';
var method = 'GET';
var xhr = createCORSRequest(method, url);
xhr.onload = function() {
alert("success");
};
xhr.onerror = function() {
alert("fail");
};
xhr.send();
提前致谢 新星
【问题讨论】:
标签: javascript html xml cors