【问题标题】:XMLHttpRequest cannot load - No 'Access-Control-Allow-Origin' header is present on the requested resource [duplicate]XMLHttpRequest 无法加载 - 请求的资源上不存在“Access-Control-Allow-Origin”标头 [重复]
【发布时间】:2014-06-03 17:28:12
【问题描述】:

错误 XMLHttpRequest 无法加载 - 请求的资源上不存在“Access-Control-Allow-Origin”标头。

//XMLHttpRequest

var xhr = new XMLHttpRequest();
if (!('withCredentials' in xhr)) { 
alert('Browser does not support CORS.'); 
return; 
} 
xhr.onerror = function() { 
alert('There was an error.'); 
}; 
xhr.onload = function() {"done"}
xhr.open("GET", "http://indicadoreseconomicos.bccr.fi.cr/indicadoreseconomicos/WebServices/wsIndicadoresEconomicos.asmx/ObtenerIndicadoresEconomicos?tcIndicador=318&tcFechaInicio=01/03/2014&tcFechaFinal=01/01/2016&tcNombre=A&tnSubNiveles=N",true);
xhr.send(null);
console.log("loading >>>")
</script>
</head>
<body>
</body>
</html>

【问题讨论】:

标签: javascript jquery web-services


【解决方案1】:

根据您的问题,答案是:

请求的资源上不存在“Access-Control-Allow-Origin”标头。

与错误中的描述完全一致。

这意味着在服务器上,您需要在响应中添加Access-Control-Allow-Origin 标头,向浏览器指示允许当前域从该主机下载。如果有问题的服务器超出了您的控制范围,那么您就不走运了,您需要在服务器端下载内容。

【讨论】:

  • 或者,更简单地说。 JFGI
  • 在开发中,您可以在浏览器中使用名为 CORS 的插件。
  • "请求的资源上没有 'Access-Control-Allow-Origin' 标头。"具体怎么做?
猜你喜欢
  • 2013-12-02
  • 2015-10-01
  • 1970-01-01
  • 2015-03-29
  • 2016-10-10
  • 1970-01-01
  • 2017-08-30
  • 2014-09-22
  • 2018-02-28
相关资源
最近更新 更多