This question already has an answer here:
这个问题已经有了答案:
- Angular.js No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access 1 answer
- 角。js没有“访问控制允许源”的标题出现在请求的资源上。因此,原点“null”不允许访问1的答案。
I am doing a an ajax get request and I am getting this error:
我在做一个ajax get请求,我得到了这个错误:
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.
I am not sure how to get around this... Here is my JS:
我不知道怎么避开这个……这是我的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)
}
})
}
});
1 个解决方案
#1
2
I changed the request to jsonp and added ?callback=JSON_CALLBACK to the end of the URL request..
我将请求更改为jsonp,并在URL请求的末尾添加了callback=JSON_CALLBACK。
var myApp = angular.module('myApp', []);
myApp.controller('mainController', function($scope, $http){
$scope.message = "hello";
var myDomain = $scope.myDomain;
$scope.searchDomain = function(myDomain){
$http.jsonp('http://domains.bootname.com/api/v1/domain/' + myDomain + '?callback=JSON_CALLBACK').then(function(result){
console.log(result.data);
});
}
});
#1
2
I changed the request to jsonp and added ?callback=JSON_CALLBACK to the end of the URL request..
我将请求更改为jsonp,并在URL请求的末尾添加了callback=JSON_CALLBACK。
var myApp = angular.module('myApp', []);
myApp.controller('mainController', function($scope, $http){
$scope.message = "hello";
var myDomain = $scope.myDomain;
$scope.searchDomain = function(myDomain){
$http.jsonp('http://domains.bootname.com/api/v1/domain/' + myDomain + '?callback=JSON_CALLBACK').then(function(result){
console.log(result.data);
});
}
});