我該如何處理jsonp響應?我試圖搜索,但我無法解決它。下面的屏幕截圖顯示了一個jsonp結果。 1 我得到使用此代碼JSONP響應,services.js在Angular JS中處理JSONP響應1.6
var app=angular.module('F1FeederApp.services', []);
app.config(function($sceDelegateProvider) {
\t $sceDelegateProvider.resourceUrlWhitelist([
'self',
'http://ergast.com/**'
]);
});
app.factory('ergastAPIservice', function($http) {
var ergastAPI = {};
var urlFiltered = 'http://ergast.com/api/f1/current/driverStandings.json';
ergastAPI.getDrivers = function() {
return $http({
method: 'JSONP',
url: urlFiltered
});
}
return ergastAPI;
});
現在,我用它下面的代碼,給我造成一號圖片訪問。
angular.module('F1FeederApp.controllers', []).
controller('driversController', function($scope, ergastAPIservice) {
$scope.nameFilter = null;
$scope.driversList = [];
// //ergastAPIservice.getDrivers() ->> when i try this i get error this is not a function.
//ergastAPIservice.getDrivers().success(function (response) {
//Dig into the responde to get the relevant data
// $scope.driversList = response.MRData.StandingsTable.StandingsLists[0].DriverStandings;
//});
//code above doesnt work so i tried to access it or atleast show a value like
// the code below
console.log(ergastAPIservice.getDrivers());
console.log(ergastAPIservice.getDrivers().MRData.StandingsTable.StandingsLists[0].DriverStandings);
});
現在我使用的console.log(JSONP響應)獲得的第一個畫面。 我該如何獲得該響應中的驅動程序列表? like:collectionVar = response.getDrivers();. 任何鏈接或相同的問題鏈接將有助於感謝!
發佈您的代碼,而不是發佈圖片 –
是它現在沒事的傢伙?謝謝 –