简体   繁体   English

从外部源中提取数据并获取请求资源上没有“ Access-Control-Allow-Origin”标头

[英]pulling data from external source and getting a No 'Access-Control-Allow-Origin' header is present on the requested resource

I am trying to pull a JS file from an external source and get the following error: 我正在尝试从外部来源提取JS文件,并出现以下错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin 'null' is therefore not allowed access. 因此,不允许访问原始“空”。

The file I am trying to pull is a JS file that has data in it. 我要提取的文件是其中包含数据的JS文件。 I have tried the following 我尝试了以下

var xhr = new XMLHttpRequest();
xhr.open("get", "https://s3-ap-southeast-2.amazonaws.com/[userid]/data.js", true);
xhr.onload = function(){  //instead of onreadystatechange
    //do something
    alert("here");
};
xhr.send(null);

I have also tried 我也尝试过

var promise = $.ajax({
    url: "https://s3-ap-southeast-2.amazonaws.com/[userid]/data.js",
    method: 'GET'
});

promise.done(function (result) {
    alert("done");
}).fail(function(){
    alert("Data cannot be loaded at this time. Please ensure there are no ad blockers enabled.");
});

I have tried this with a JSON file and these works but it will not load in the JS file. 我已经尝试过使用JSON文件执行此操作,但是这些方法无法在JS文件中加载。 Can anyone shed any light? 谁能阐明任何想法?

您需要在获取数据的响应中添加CORS标头。没有其他方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Flask API 获取“请求的资源上不存在‘Access-Control-Allow-Origin’标头” - Getting "No 'Access-Control-Allow-Origin' header is present on the requested resource" from Flask API 请求的资源上不存在“Access-Control-Allow-Origin”header——当尝试从 REST API 获取数据时 - No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API Javascript-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - Javascript - No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在“Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource 角度4-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - Angular 4 - No 'Access-Control-Allow-Origin' header is present on the requested resource NodeJ在所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - NodeJs No 'Access-Control-Allow-Origin' header is present on the requested resource Access-Control-Allow-Origin header 存在于请求的资源上 - Access-Control-Allow-Origin header is present on the requested resource 请求的资源 .htaccess 上不存在 Access-Control-Allow-Origin 标头 - No Access-Control-Allow-Origin header is present on the requested resource .htaccess XMLHttpRequest请求的资源上没有“Access-Control-Allow-Origin”标头 - XMLHttpRequest No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在Access-Control-Allow-Origin标头 - Access-Control-Allow-Origin header is not present on the requested resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM