我正面临"访问控制来源不允许" AngularJS中的问题并基于AngularJS CORS Issues我在我的代码中添加了以下行:
angular.module('app', [
'ngRoute',
'appModules.filters',
'appModules.ajaxCallService'
])
.config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$routeProvider.when('/login', {templateUrl: 'views/login.html', controller: 'LoginCtrl'});
}]);
但我仍面临问题:
XMLHttpRequest cannot load http://127.0.0.1:8000/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
有人可以帮我解决这个问题吗?
即使在URL中使用localhost,我也会遇到同样的问题
XMLHttpRequest cannot load http://localhost:8000/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
我正在使用AngularJS版本1.2.16并使用0.10.26 nodejs表达.JS。
答案 0 :(得分:3)
我的问题得到了解决我添加了
res.setHeader('Access-Control-Allow-Origin', 'http://localhost');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
在我的快速JS代码中将数据发送到客户端应用程序。