[英]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.