XMLHttpRequest无法加载-请求的资源上不存在"Access-Control-Allow-Origin"标头 [英] XMLHttpRequest cannot load - No 'Access-Control-Allow-Origin' header is present on the requested resource

查看:197
本文介绍了XMLHttpRequest无法加载-请求的资源上不存在"Access-Control-Allow-Origin"标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误XMLHttpRequest无法加载-请求的资源上没有'Access-Control-Allow-Origin'标头.

ERROR XMLHttpRequest cannot load - No 'Access-Control-Allow-Origin' header is present on the requested resource.

//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>

推荐答案

按照您的问题的精神,答案是:

In the spirit of your question, the answer is:

请求的资源上没有"Access-Control-Allow-Origin"标头.

No 'Access-Control-Allow-Origin' header is present on the requested resource.

与错误中所述完全相同.

Exactly as described in the error.

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

This means that at the server, you need to add an Access-Control-Allow-Origin header to the response that indicates to the browser that the current domain is permitted to download from this host. If the server in question is out of your control, then you're out of luck and you'll need to download the content server-side.

这篇关于XMLHttpRequest无法加载-请求的资源上不存在"Access-Control-Allow-Origin"标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆