2013-03-16 37 views
0

我刚刚开始对AngularJS和由于某种原因,我有一个问题。我正在对Last.fm API运行http get查询以检索类似的艺术家Caravan。我已经在Web浏览器上试过了这个查询,并且它返回了正确的XML响应。

这是我的控制器:

function ArtistsCtrl($scope, $http) { 
    //artist: $scope.artist; 
    $scope.getArtists = function() { 
     $http.get('http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=Caravan&api_key=MY_API_KEY').success(function(data) { 
      echo(data); 
     }).error(function(data, status, headers, config){ 
      echo(data); 
     }); 
    }; 
}; 

这是我的看法:

<!doctype html> 
<html lang="en" ng-app> 
<head> 
<meta charset="utf-8"> 
<title>My HTML File</title> 
<link rel="stylesheet" href="css/app.css"> 
<link rel="stylesheet" href="css/bootstrap.css"> 
</head> 
<body> 
    <div ng-controller="ArtistsCtrl"> 
     <button ng-click="getArtists()">Get artists</button> 
    </div> 
    <script src="angular.js"></script> 
    <script src="angular-resources.js"></script> 
    <script src="app.js"></script> 
</body> 
</html> 

的问题是,当我按一下按钮,它执行$ http.get,它抛出发生异常并永不返回任何数据。

[Exception... "" nsresult: "0x805e0006 (<unknown>)" location: "JS frame :: http://localhost/AngularJS/angular.js :: createHttpBackend/< :: line 9409" data: no] 
http://localhost/AngularJS/angular.js 
Line 5764 

任何人有任何想法可能是什么问题?谢谢。

+1

我没有看到任何立即错误的(除非你应该使用'params'选项来为你的URL参数)。在Plunker中,我得到了预期的403。如果你将API KEY添加到这个Plunker,它是否工作? http://plnkr.co/edit/X4bcSlCu2Wh5yzbreyCo?p=preview – 2013-03-16 18:12:02

+1

'artist:$ scope.artist;'不是有效的JavaScript。 – Stewie 2013-03-16 18:12:54

+0

是乔希,完美的工作在蹲跳者身上。我也尝试在Plunker上使用我以前使用的getArtists函数,它的作用就像一个魅力。我现在会尝试redownloading angular.js。 – Uri 2013-03-16 18:31:57

回答

0

尝试下载AngularJS 1.0.5,它工作正常,它给我在1.1.3上的错误。