0

我正在尝试为 OTP 实现实现 nexmoverify REST API,但响应对象 comig 为 null。我签入 Postman 并能够从响应对象中获取字符串化对象。

var app = angular.module('angularjs-starter', []);
app.config(['$httpProvider', function($httpProvider) {
   $httpProvider.defaults.useXDomain = true;
   delete $httpProvider.defaults.headers.common['X-Requested-With'];
}
]);

app.controller('MainCtrl', function($scope, $http) {


   $scope.addNewChoice = function () {
      console.log('aaaa');
      $scope.res=$http.get("https://api.nexmo.com/verify/json?api_key=56a9b1af&api_secret=XXXXXX&number=919650298011&brand=stayuncle").
         success(function (response) {
            $scope.res = response.data;


         }).
      error(function (response){
            console.log(response);

            $scope.res = response.data;


         });


   };

代码流程:code flow coming to error() section and then printing null in web console.

错误 :

Response object coming null as well as getting this error in web console 

XMLHttpRequest cannot load https://api.nexmo.com/verify/json?api_key=56X9b1af&api_secret=d3XXXX&number=91XX50298011&brand=stayuncle. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

有人可以帮我解决这个问题。

4

1 回答 1

0

错误告诉你问题所在。

请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许访问源“ http://localhost:8080 ”。

未针对 CORS 配置 REST API 服务器,因此,不允许您从除https://api.nexmo.com/域之外的任何来源访问该 URL。但是,您不应该使用 JSONP 吗?

关于 CORS 的参考

JSONP 参考

于 2015-07-15T19:20:33.923 回答