没有“访问控制-允许-原点”--->做一个角$HTTP请求[复制]

时间:2022-04-19 18:12:26

This question already has an answer here:

这个问题已经有了答案:

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);
        });
    }

});