在Javascript中跳过循环中的错误

时间:2015-01-06 05:12:13

标签: javascript jquery angularjs loops rss

我正在尝试使用Google的Feed API来使用AngularJS控制器内的Feed来获取图像。它会成功获得三张图片,然后它会点击一个推特网址,这会让人感到困惑并打破脚本。我希望它跳过它并继续加载图像。反正有吗?

错误:

Error: Syntax error, unrecognized expression: submitted by <a href="http://www.reddit.com/user/lachlan_jp"> lachlan_jp </a> <br> <a href="https://twitter.com/caseandpointdjs/status/552222732994482178">[link]</a> <a href="http://www.reddit.com/r/Monstercat/comments/2rg0nr/case_points_new_single_will_be_premiering/">[8 comments]</a>

代码:

$http.get("http://ajax.googleapis.com/ajax/services/feed/load", { params: { "v": "1.0", "q": "http://www.reddit.com/r/monstercat/.rss", "num": "100" } })
            .success(function(data) {
                $scope.rssTitle = data.responseData.feed.title;
                $scope.rssUrl = data.responseData.feed.feedUrl;
                $scope.rssSiteUrl = data.responseData.feed.link;
                $scope.entries = data.responseData.feed.entries;

                var data = data.responseData.feed;

                var findFirstImage = data.entries.content;
                angular.forEach(data.entries, function(value){
                  value.sapleImage =     $(value.content).find('img').eq(0).attr('src');
                  console.log(value.sapleImage);
                })



            })
            .error(function(data) {
                console.log("ERROR: " + data);
            });
    }

1 个答案:

答案 0 :(得分:0)

您是否尝试使用无效的try:catch块?

try {
$http.get("http://ajax.googleapis.com/ajax/services/feed/load", { params: { "v": "1.0", "q": "http://www.reddit.com/r/monstercat/.rss", "num": "100" } })
            .success(function(data) {
                $scope.rssTitle = data.responseData.feed.title;
                $scope.rssUrl = data.responseData.feed.feedUrl;
                $scope.rssSiteUrl = data.responseData.feed.link;
                $scope.entries = data.responseData.feed.entries;

                var data = data.responseData.feed;

                var findFirstImage = data.entries.content;
                angular.forEach(data.entries, function(value){
                  value.sapleImage =     $(value.content).find('img').eq(0).attr('src');
                  console.log(value.sapleImage);
                })



            })
            .error(function(data) {
                console.log("ERROR: " + data);
            });
    }
}
catch(err) {
    Console.log('Got an error'); // or just pass/continue/return true/any way of doing nothing
}