CORS政策被屏蔽

时间:2018-10-29 08:19:43

标签: google-chrome-extension

我创建了简单的Google chrome扩展名,并获取了JSON数据,但生成了此错误

dashboard.html:1 Access to XMLHttpRequest at 'https://humane-like-developer-edition.ap4.force.com/services/apexrest/SessionHuman' from origin 'chrome-extension://dgbedclgdamcknolmpacbbigocadoiko' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

这是我的代码

var HttpClient=function()
{
    this.get=function(aUrl,aCallback)
    {
        var anHttpRequest=new XMLHttpRequest();
        anHttpRequest.onreadystatechange=function()
        {
            if(anHttpRequest.readyState==4 && anHttpRequest.status==200)
            {
                aCallback(anHttpRequest.responseText);
            }
        }
        anHttpRequest.open("GET",aUrl,true);
        anHttpRequest.send(null);
    }
}
var theurl='https://humane-like-developer-edition.ap4.force.com/services/apexrest/SessionHuman';
var client=new HttpClient();
client.get(theurl,function(response){
alert(response);

1 个答案:

答案 0 :(得分:0)

请求的资源上没有“ Access-Control-Allow-Origin”标头。

请求的资源必须响应与您的Access-Control-Allowed-Origin请求标头匹配的Origin标头。

如果它是公共API,则应使用*进行响应。 注意:如果协议不是*,则它是响应的类型,不允许,并且不允许使用通配符。