Javascript 找不到AngularJS GET 404
目前正在开发Angular JS tv应用程序。应用程序通过api调用获取数据。我正在尝试从结果数组中获取图像 以下是mainController.js的代码Javascript 找不到AngularJS GET 404,javascript,angularjs,http-status-code-404,Javascript,Angularjs,Http Status Code 404,目前正在开发Angular JS tv应用程序。应用程序通过api调用获取数据。我正在尝试从结果数组中获取图像 以下是mainController.js的代码 app.controller("mainController", function($scope, $http){ $scope.apiKey = "b3e2e6f87d3aeec3075668a1bd4a78e2"; $scope.init = function(){ //api call require
app.controller("mainController", function($scope, $http){
$scope.apiKey = "b3e2e6f87d3aeec3075668a1bd4a78e2";
$scope.init = function(){
//api call requires format, apiKey, date, and days
var today = new Date();
//format apiDate according to the api specifications
var apiDate = today.getFullYear() + ("0" + (today.getMonth()+1)) + today.getDate();
$scope.results = [];
console.log(apiDate);
$http.jsonp('http://api.trakt.tv/calendar/premieres.json/' + $scope.apiKey + '/' + apiDate + '/' + 30 + '/?callback=JSON_CALLBACK').success(function (data){
//connection successful
//console.log(data);
angular.forEach(data, function (value, index){
var date = value.date;//stores the date of the tv shows
angular.forEach(value.episodes, function (tvshow, index){
//this adds the locally store date to the tvshow object
tvshow.date = date;
$scope.results.push(tvshow);
});//end 2nd for each
});//end 1st for each
}).error(function (error){
//connection failed
});
};
});
下面是index.html的代码
<ul class="episode-list">
<li ng-repeat="tvshow in results">
<div class="row-fluid">
<div class="span3">
<img src="{{tvshow.episode.images.screen}}"/>
</div>
</div>
</li>
</ul>
-
控制台返回以下错误:
获取://localhost/tvApp/%7B%7Btvshow.eption.images.screen%7D%7D 404(未找到)localhost/:29
获取//localhost/tvApp/%7B%7Btvshow.eption.images.screen%7D%7D 404(未找到)
angular.min.js:20
我不太清楚为什么会发生这种情况。任何帮助都将不胜感激。我一直在寻找类似的问题,但没有成功检查以确保您的成功回调确实触发
检查以确保您的电视节目包含剧集、图像和屏幕。没有拼写错误?使用
ng src
代替src
:
<img ng-src="{{tvshow.episode.images.screen}}">
这可以防止在AngularJS处理角度标记之前加载图像。使用
src
将加载文本urlhttp://www.mydomain.com/{{tvshow.eption.images.screen}
您的代码没有问题,可能您获取$http的链接在逻辑上不正确,您的所有代码都正确。由于$scope.results数组已填充,因此正在触发成功回调。您需要查看其他代码吗?我遵循这个例子:伟大的解决方案。