2014-11-22 54 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); 
     }); 
    } 

}); 
相關問題