【发布时间】:2018-10-29 17:28:13
【问题描述】:
我创建了简单的 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);
【问题讨论】:
-
Understanding CORS的可能重复