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
任何人有任何想法可能是什麼問題?謝謝。
我沒有看到任何立即錯誤的(除非你應該使用'params'選項來爲你的URL參數)。在Plunker中,我得到了預期的403。如果你將API KEY添加到這個Plunker,它是否工作? http://plnkr.co/edit/X4bcSlCu2Wh5yzbreyCo?p=preview – 2013-03-16 18:12:02
'artist:$ scope.artist;'不是有效的JavaScript。 – Stewie 2013-03-16 18:12:54
是喬希,完美的工作在蹲跳者身上。我也嘗試在Plunker上使用我以前使用的getArtists函數,它的作用就像一個魅力。我現在會嘗試redownloading angular.js。 – Uri 2013-03-16 18:31:57