[英]Response Object coming null for get request for rest api
我试图为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.
有人可以帮我解决这个问题。
该错误告诉您问题所在。
所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问源' http:// localhost:8080 '。
未为CORS配置REST API服务器,因此,除https://api.nexmo.com/域之外,您不能从任何其他来源访问该URL。 但是,您不应该使用JSONP吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.