【发布时间】:2013-12-20 14:03:51
【问题描述】:
我在controller.js中有如下代码,
var myApp = angular.module('myApp',[]);
myApp.service('dataService', function($http) {
delete $http.defaults.headers.common['X-Requested-With'];
this.getData = function() {
$http({
method: 'GET',
url: 'https://www.example.com/api/v1/page',
params: 'limit=10, sort_by=created:desc',
headers: {'Authorization': 'Token token=xxxxYYYYZzzz'}
}).success(function(data){
return data
}).error(function(){
alert("error");
});
}
});
myApp.controller('AngularJSCtrl', function($scope, dataService) {
$scope.data = dataService.getData();
});
但是,我想我可能在 CORS 相关问题上犯了一个错误。你能指点我打这个电话的正确方法吗?非常感谢!
【问题讨论】:
-
这是一个超级常见的问题:)
标签: javascript angularjs http get cross-domain