2014-11-22 100 views
-1

我做了一个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. 

我不知道怎么样要解决这个问题......这是我的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

'domains.bootname .COM '必须发送必要的HTTP头来允许这个。 – CBroe 2014-11-22 23:00:26

回答

2

我改JSONP请求,并加入回调= JSON_CALLBACK到URL请求结束..

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

}); 
相关问题