javascript 未找到 AngularJS GET 404

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24232273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 02:25:26  来源:igfitidea点击:

AngularJS GET 404 Not Found

javascriptangularjshttp-status-code-404

提问by Tarang Hirani

Currently working on an Angular JS tv application. The app gets data from an api call. I am trying to obtain the images from the results array.

目前正在开发 Angular JS 电视应用程序。该应用程序从 api 调用中获取数据。我正在尝试从结果数组中获取图像。

Here's the code for the mainController.js

这是 mainController.js 的代码

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
        });
    };  
});

Here's the code for the index.html

这是 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>

The console returns the following errors:

控制台返回以下错误:

GET : //localhost/tvApp/%7B%7Btvshow.episode.images.screen%7D%7D 404 (Not Found) localhost/:29

GET : //localhost/tvApp/%7B%7Btvshow.episode.images.screen%7D%7D 404 (未找到) localhost/:29

GET //localhost/tvApp/%7B%7Btvshow.episode.images.screen%7D%7D 404 (Not Found) angular.min.js:20

GET //localhost/tvApp/%7B%7Btvshow.episode.images.screen%7D%7D 404(未找到)angular.min.js:20

I am not quite sure why this is happening. Any help would be appreciate. I have been looking around for a similar issue but no success

我不太确定为什么会发生这种情况。任何帮助将不胜感激。我一直在寻找类似的问题,但没有成功

回答by NoWhereToBeSeen

Use ng-srcinstead of src:

使用ng-src代替src

<img ng-src="{{tvshow.episode.images.screen}}">

This prevents the image from being loaded before the Angular markup is processed by AngularJS. Using srcwill load the literal url http://www.mydomain.com/{{tvshow.episode.images.screen}}.

这可以防止在 AngularJS 处理 Angular 标记之前加载图像。使用src将加载文字 url http://www.mydomain.com/{{tvshow.episode.images.screen}}

回答by possiblyLethal

Check to make sure your success callback is actually triggering.

检查以确保您的成功回调实际上正在触发。

Check to make sure your tvshow contains episodes, which contains images, which contains screen. No misspellings?

检查以确保您的电视节目包含剧集,其中包含图像,其中包含屏幕。没有拼写错误?