我正在尝试为OTP实现实现nexmoverify REST API,但是响应对象comig null。我在Postman中检查并且能够从响应对象获取stringify对象。
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.
有人可以帮我解决这个问题。
答案 0 :(得分:0)
错误告诉您问题。
否'访问控制 - 允许 - 来源'标题出现在请求的上 资源。起源' http://localhost:8080'因此是不允许的 访问。
未为CORS配置REST API服务器,因此,不允许您从https://api.nexmo.com/域以外的任何来源访问该URL。但是,你不应该使用JSONP吗?