I'm getting this error using ngResource to call a REST API on Amazon Web Services:(我在使用ngResource调用Amazon Web Services上的REST API时遇到此错误:)
XMLHttpRequest cannot load http://server.apiurl.com:8000/s/login?login=facebook .(XMLHttpRequest无法加载http://server.apiurl.com:8000/s/login?login=facebook 。) Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.(对预检请求的响应未通过访问控制检查:请求的资源上不存在“ Access-Control-Allow-Origin”标头。) Origin ' http://localhost ' is therefore not allowed access.(因此,不允许访问源“ http:// localhost ”。) Error 405(错误405)
Service:(服务:)
socialMarkt.factory('loginService', ['$resource', function($resource){
var apiAddress = "http://server.apiurl.com:8000/s/login/";
return $resource(apiAddress, { login:"facebook", access_token: "@access_token" ,facebook_id: "@facebook_id" }, {
getUser: {method:'POST'}
});
}]);
Controller:(控制器:)
[...]
loginService.getUser(JSON.stringify(fbObj)),
function(data){
console.log(data);
},
function(result) {
console.error('Error', result.status);
}
[...]
I'm using Chrome, and I dont know what else to do in order to fix this problem.(我正在使用Chrome,但我不知道该怎么做才能解决此问题。) I've even configured the server to accept headers from origin localhost
.(我什至将服务器配置为接受源localhost
标头。)
ask by Andre Mendes translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…