Angularjs YQL 的 $http 不工作?

Angularjs $http for YQL not working?

我是新手angular js 开发者。最近我正在尝试构建一个使用 Yahoo 查询语言 (YQL) 的应用程序。我实际上需要数据 table 中的 cricket.teams 数据。因此,我只是使用 Yahoo 提供的 REST 查询从 angularjs 的控制器发出 $http 请求。

这是我的看法:

<div ng-controller="ProfileCtrl">
    <div style="height:80vh">
    {{Hello}}   
    </div>
</div>

这是我的控制器

app.controller('ProfileCtrl',function($scope,$http){
    $scope.Hello='Welcome';
    var url ='https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20cricket.teams&format=json&diagnostics=true&env=store%3A%2F%2F0TxIGQMQbObzvU4Apia0V0&callback=';
// Simple GET request example :
$http.get(url).
  success(function(data, status, headers, config) {
alert(data);
  }).
  error(function(data, status, headers, config) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
 alert('error'+status); 
  });
});

它正在返回状态为 0 的错误。这意味着存在某种错误。我在这里做错了什么??

注意。我试过 $http.jsonp() 。并给出相同的结果。

如果你得到 status 0 那么这可能是由于 illegal cross-origin request

尽管您的代码功能齐全,但请在此处查看相关插件 http://plnkr.co/edit/xFAnI7

正在关注 api 通话

$http.get(url).then(function(response) {
  $scope.response = angular.toJson(response.data);
}).catch(function(response) {
  $scope.response = response;
});

会不会return像

{"query":{"count":14,"created":"2015-05-05T10:38:27Z","lang":"fi-FI","diagnostics":{"cache":{"execution-start-time":"0","execution-stop-time":"3","execution-time":"3","method":"GET","type":"MEMCACHED","content":"TABLE.yql-query-yahooapis-com.v1.production.manhattan.bf1.yahoo.com.cricket.teams.cb28f8540307fdb68289fa5fedc2b832"},"url":[{"execution-start-time":"4","execution-stop-time":"9","execution-time":"5", ... etc etc