AngularJS RESTAPI调用抛出错误
我在学AngularJS。我试图使用标准的AngularJS RESTAPI调用抛出错误,angularjs,Angularjs,我在学AngularJS。我试图使用标准的$http服务进行RESTapi调用,但没有得到成功的响应。知道我做错了什么吗 我正在调用URL(当我ping它时,URL呈现良好): 我收到的错误是: {"data":null,"status":0,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://finance.yahoo.com/webservice/v1/symb
$http
服务进行RESTapi调用,但没有得到成功的响应。知道我做错了什么吗
我正在调用URL(当我ping它时,URL呈现良好):
我收到的错误是:
{"data":null,"status":0,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote","params":{"format":"json"},"headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""}
我的Angularjs测试代码是:
angular.element(document).ready(function(){
angular.bootstrap(document.getElementById('app2'),['app2']);
});
angular.module('app2',[])
.controller('testNamesCtrl',function($scope,$http){
$http({method:'GET',url:'http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote',params:{format:"json"}})
.then(
function(response){
$scope.record = response.data;
$scope.record1 = response;
}, function(response){
$scope.record1 = response;
});
});
据我所知,您尝试提出跨域请求。你可以试着用这个。但只有在服务器允许使用的情况下,它才能工作 正如我看到的,这个服务器是不允许的。在这种情况下,您可以在服务器上准备数据
echo file_get_contents(url);
您得到的HTTP状态码是什么?检查浏览器控制台(网络选项卡),可能已经有了一些线索..jsonp可能是注释中建议的答案。以下是错误-XMLHttpRequest无法加载。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“”。testNamesCtrl.js:36对象{数据:null,状态:0,配置:对象,状态文本:'}非常感谢!