I keep encountering a 400 error when attempting to fetch the JSON data from the following URL using $http.get.
$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 occurred");
});
However, I succeed in retrieving it using this alternative method:
$.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");});
The issue arises when trying to update a value in my $scope, as it only reflects in the view after one action, causing me to display outdated song information instead of the current one.
Below is the controller code snippet:
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 occurred");
});
$.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);
});
});
}
Your assistance on this matter is greatly appreciated.