Jquery XmlHttpRequest无法加载,因为它被CORS策略阻止:No';访问控制允许原点';请求的资源上存在标头

Jquery XmlHttpRequest无法加载,因为它被CORS策略阻止:No';访问控制允许原点';请求的资源上存在标头,jquery,json,xmlhttprequest,cors,Jquery,Json,Xmlhttprequest,Cors,如何创建源标题,使其适用于所有设备上的所有域和浏览器?我是否使用某种回调?我应该把这个放在我的代码中的什么地方 var characters = [ "http://www.anapioficeandfire.com/api/characters/148", "http://www.anapioficeandfire.com/api/characters/823", "http://www.anapioficeandfire.com/api/characters/1052", "http://

如何创建源标题,使其适用于所有设备上的所有域和浏览器?我是否使用某种回调?我应该把这个放在我的代码中的什么地方

var characters = [

"http://www.anapioficeandfire.com/api/characters/148",
"http://www.anapioficeandfire.com/api/characters/823",
"http://www.anapioficeandfire.com/api/characters/1052",
"http://www.anapioficeandfire.com/api/characters/1303",
"http://www.anapioficeandfire.com/api/characters/208",

];



$(".btn").click(clickButton);


function clickButton(e) {

e.preventDefault();

var i = $(this).attr("data-id");
console.log(characters[i]);

var data;

$.getJSON(characters[i], function(json) {
    data = json;

)};

如果您尝试通过HTTPS而不是HTTP调用API,它会工作(我现在就尝试了)

您将收到该错误消息,因为服务器正在发送重定向响应(
HTTP/1.1 301
。请参阅
位置
标题),而不发送CORS标题。正如你在这里看到的:

$ curl -v http://www.anapioficeandfire.com/api/characters/148 * Trying 104.27.137.190... * TCP_NODELAY set * Connected to www.anapioficeandfire.com (104.27.137.190) port 80 (#0) GET /api/characters/148 HTTP/1.1 Host: www.anapioficeandfire.com User-Agent: curl/7.51.0 Accept: */* HTTP/1.1 301 Moved Permanently Date: Sun, 21 May 2017 21:43:13 GMT Transfer-Encoding: chunked Connection: keep-alive Set-Cookie: __cfduid=d59cc58d4e217f93147944a7f5ae1b6231495402993; expires=Mon, 21-May-18 21:43:13 GMT; path=/; domain=.anapioficeandfire.com; HttpOnly Cache-Control: max-age=3600 Expires: Sun, 21 May 2017 22:43:13 GMT Location: https://www.anapioficeandfire.com/api/characters/148 Server: cloudflare-nginx CF-RAY: 362ab5c495ec42fe-MXP


如何通过HTTPS而不是HTTP调用API?我是否使用命令行?它适用于所有浏览器吗?我试过这样做,但对我来说不起作用。如果你能得到和以前一样的答案,试着使用类似于我的代码示例的东西。这是我现在的网站:@FrederickAlcantara你仍然在使用HTTP。查看您在数组中使用的URL(var characters=[…])如何将这些URL更改为HTTPS?它会回到你以前做的事情吗?