我是使用 angularJS 作为我的客户端开发网站的新手,我正在尝试使用 $http.get 方法通过 API 调用访问我的 JSON。
我的问题是我的 API 调用需要访问令牌。每当我尝试刷新我的页面时,我总是收到此错误。
XMLHttpRequest 无法加载http://unexus-api-dev-3urcgetdum.elasticbeanstalk.com/drugstores。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' http://localhost:8888 '。
我目前正在使用此代码来获取我的数据。
myApp.controller('loginCtrl', function($scope, $http) {
$http.get("http://unexus-api-dev-3urcgetdum.elasticbeanstalk.com/drugstores")
.then(function(response) {
$scope.names = response.data.records;
});
});Run Code Online (Sandbox Code Playgroud)
我如何在 $http.get 方法上插入访问令牌。