【发布时间】:2016-08-09 15:59:12
【问题描述】:
目前我正在开发 JHipster 3(从 JHipster 2 迁移)。 RESFTful 请求我的一些模块来获取 JSON 数据。
这里是 JHipster 2 中的示例代码:-->(工作)
'use strict';
angular.module('newsletterApp')
.factory('UserBirthday', function ($resource) {
return $resource('http://localhost:8081/BirthDay/Rest/WebService/GetFeeds', {}, {
'query': {method: 'GET', isArray: true},
'get': {
method: 'GET',
isArray: true,
transformResponse: function (data) {
data = angular.fromJson(data);
return data;
}
}
});
});
对于 Jhipster 3:
(function(){
'use strict';
angular
.module('newsletterApp')
.factory('EmployeeBirthday', EmployeeBirthday);
EmployeeBirthday.$inject = ['$resource'];
function EmployeeBirthday($resource){
return $resource('http://localhost:8081/BirthDay/Rest/WebService/GetFeeds', {}, {
'query': {method: 'GET', isArray: true},
'get': {
method: 'GET',
isArray: true,
transformResponse: function (data) {
data = angular.fromJson(data);
return data;
}
}
});
} })();
我得到了错误:
XMLHttpRequest cannot load http://localhost:8081/BirthDay/Rest/WebService/GetFeeds. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
在 application.yml 中也已经为 CORS 启用
cors: #By default CORS are not enabled. Uncomment to enable.
allowed-origins: "*"
allowed-methods: GET, PUT, POST, DELETE, OPTIONS
allowed-headers: "*"
exposed-headers:
allow-credentials: true
max-age: 1800
有解决这个问题的建议吗?
【问题讨论】:
标签: angularjs rest cors jhipster