【发布时间】:2016-05-27 16:42:02
【问题描述】:
我正在尝试通过连接到 RESTful API 来使用 AngularJS $http 服务进行 ajax 调用。
我得到的结果:
XMLHttpRequest 无法加载 http://hostname:8080/abc/test。不 请求中存在“Access-Control-Allow-Origin”标头 资源。因此不允许访问 Origin 'null'。
我知道我正在做一个XMLHttpRequest to a different domain。所以浏览器会阻止它,因为出于安全原因,它通常允许来自同一来源的请求。
要求的代码:
$http({
method: 'GET',
cache: true,
url: "http://hostname:8080/abc/test"
}).then(function successCallback(response) {
console.log(response);
}, function errorCallback(response) {
});
我阅读了很多关于 stackoverflow 的问题:
No 'Access-Control-Allow-Origin' header is present on the requested resource error
Access-Control-Allow-Origin header
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '…' is therefore not allowed access
但没有成功。 任何直接的帮助都将是非常可观的。谢谢
【问题讨论】:
标签: javascript angularjs ajax http cross-domain