gpt4 book ai didi

javascript - 跳过 Javascript 循环中的错误

转载 作者:行者123 更新时间:2023-11-28 07:43:02 25 4
gpt4 key购买 nike

我正在尝试使用 Google 的 Feed API 通过 AngularJS Controller 内的 feed 来获取图像。它将成功获取三个图像,然后它会点击 Twitter URL,它会变得困惑并破坏脚本。我希望它跳过这一点并继续加载图像。有办法做到这一点吗?

错误:

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

最佳答案

您是否尝试过使用不执行任何操作的 try:catch block ?

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
}

关于javascript - 跳过 Javascript 循环中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27792452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com