当我尝试从以下URL使用$ http.get检索JSON时,出现错误400。
$http.get('https://api.spotify.com/v1/search?q=artist:Owl+City+title:On+The+Wing&type=track&limit=1').
success(function(data) {
console.log("Success");
})
.error(function(error, status, headers, config) {
console.log(status);
console.log("Error occured");
});
我设法与该检索:
$.getJSON('https://api.spotify.com/v1/search?q=artist:Owl+City+title:On+The+Wing&type=track&limit=1').then(function (data) { console.log("Success");});
但问题是,当我尝试在我的$范围更改值用这种方法,这只是显示在视图,之后的一个动作,因为我得到了以前的歌曲信息而不是现在的歌曲。
这里是控制器代码:
angular.module('pwilApp')
.controller('SongsCtrl', function ($rootScope, $scope,$http,$sce) {
var increment = 0;
var laSimilaire = "";
var init = true;
$rootScope.activeHome = "";
$rootScope.activeSongs = "active";
$rootScope.activeAccount = "";
$rootScope.activeContacts = "";
$rootScope.activeAbout = "";
$rootScope.activeConnection = "";
$scope.currentPage = 1;
$scope.totalPages = 0;
$scope.loading = true;
$scope.$on('$viewContentLoaded', function() {
$http.get('https://api.spotify.com/v1/search?q=artist:Owl+City+title:On+The+Wing&type=track&limit=1').success(function (data) {
console.log("Success");
})
.error(function (error, status, headers, config) {
console.log(status);
console.log("Error occured");
});
$.getJSON('https://api.spotify.com/v1/search?q=artist:Owl+City+title:On+The+Wing&type=track&limit=1').then(function (data) {
$scope.preview_url = $sce.trustAsResourceUrl(data.tracks.items[0].preview_url);
});
});
}
谢谢您的anwser。
你可以张贴控制器代码,你正在做的电话吗? – rick
您的数据出现故障时,请尝试使用其他浏览器/计算机。代码本身似乎很好 – Und3rTow