【发布时间】:2015-01-20 21:42:00
【问题描述】:
我正在执行一个 ajax 获取请求,但出现此错误:
XMLHttpRequest cannot load http://domains.bootname.com/api/v1/domain/test. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
我不确定如何解决这个问题...这是我的 JS:
var myApp = angular.module('myApp', []);
myApp.controller('mainController', function($scope, $http){
$scope.message = "hello";
var myDomain = $scope.myDomain;
$scope.searchDomain = function(myDomain){
$http.get('http://domains.bootname.com/api/v1/domain/' + myDomain, {
type: 'GET',
dataType: 'JSONP',
success: function(results){
console.log(results)
}
})
}
});
【问题讨论】:
-
domains.bootname.com必须发送必要的 HTTP 标头以允许这样做。
标签: angularjs http cors angular-http