(RSS Feed)Uncaught TypeError:无法读取未定义的属性“title”

时间:2021-11-17 07:18:42

I am trying to pick content from a Google Blogger Feed that is http://testdevchuli.blogspot.com/feeds/posts/default?redirect=false&orderby=published&alt=json-in-script&callback=exeRSSpostReader&max-results=500 through using the JavaScript code at http://testdevchuli.blogspot.com/ where you can see the error through Inspect Element section where there is only one red warning that is...

我正在尝试使用JavaScript从Google Blogger Feed中选择内容http://testdevchuli.blogspot.com/feeds/posts/default?redirect=false&orderby=published&alt=json-in-script&callback=exeRSSpostReader&max-results=500 http://testdevchuli.blogspot.com/上的代码,您可以通过Inspect Element部分查看错误,其中只有一个红色警告是......

Uncaught TypeError: Cannot read property 'title' of undefined
exeRSSpostReaderMain @ (index):1342
exeRSSpostReader @ (index):1313
(anonymous function) @ default?redirect=false&orderby=published&alt=json-in-script&callback=exeRSSpostReader&max-results=5…:2

So why its happening...??? Here is my full code from the upper link...

那么为什么会发生...... ???这是我上层链接的完整代码......

<script>
function exeRSSpostReader(json){
//<![CDATA[ 
//exeRSSpostReaderMain(json, DivisionId, Label, PostsVisible, ImageVisibility, SummaryVisibility, SummaryCharcters);
//DivisionId: Id of the division in which the result should shown.
//Label: Specific Label, Set &quot;&quot; for all posts.
//PostsVisible: No of posts shown in final result.
//ImageVisibility: Set true if you want thumbnails else set false.
//SummaryVisibility: Set true if you want summary else set false.
//SummaryCharcters: No of character shown in summary.
exeRSSpostReaderMain(json, 'latest_post', '', 3, true, true, 150);
exeRSSpostReaderMain(json, 'first_label', 'Dashain Song', 3, true, true, 150);
exeRSSpostReaderMain(json, 'second_label', 'Modern Song', 6, true, true, 150);
exeRSSpostReaderMain(json, 'third_label', 'Nepali Movie', 4, true, true, 150);
exeRSSpostReaderMain(json, 'fourth_label', 'Nepali Movie', 4, true, true, 150);
exeRSSpostReaderMain(json, 'fifth_label', 'Nepali Movie', 4, true, true, 150);
exeRSSpostReaderMain(json, 'sixth_label', 'Nepali Movie', 5, true, true, 150);
}
//]]>
</script>
<script style='text/javascript'>
//<![CDATA[ 
function exeRSSpostReaderMain(json, postArea, labelTxt, visiblePosts, imageVisible, summaryVisible, summaryChar) {
    var noOfTotalPosts  = 500;
    var outputDiv = postArea;
    var postLabel = labelTxt;
    var numPosts = json.feed.openSearch$totalResults.$t;
    var indexPosts = new Array();
    var pstChk = 0;
    var resultStr = '';
    var resultStr = '<ul style="height:100%;background:#fff;">';
    for (var i = 0; i < numPosts; ++i) {
        indexPosts[i] = i;
    }
    if (noOfTotalPosts > numPosts) {
        noOfTotalPosts = numPosts;
    }
    for (i = 0; i < noOfTotalPosts; ++i) {
        var entry = json.feed.entry[indexPosts[i]];
        var postTitle =  entry.title.$t;
        for (var k = 0; k <  entry.link.length; k++) {
            if ( entry.link[k].rel == 'alternate') {
                postURL =  entry.link[k].href;
                break;
            }
        }
        if ("content" in entry) {
            var postContent = entry.content.$t
        }
        s = postContent;
        a = s.indexOf("<img");
        b = s.indexOf("src=\"", a);
        c = s.indexOf("\"", b + 5);
        d = s.substr(b + 5, c - b - 5);
        if ((a != -1) && (b != -1) && (c != -1) && (d != "")) {
            var imageUrl = d
        } else var imageUrl = 'https://lh6.googleusercontent.com/-cXUE46Oenac/U6rONTOCYuI/AAAAAAAAQTw/r_WI91TMLpk/s400/Images_no_image.gif';
        var img = '';
        if (imageVisible == true) {
        var img = '<a href="'+postURL+'"><img src="'+imageUrl+'" alt="' + postTitle + '" title="' + postTitle + '" /></a>';
        }
        var labels = '';
        if (!entry.category){
            var noLabel = "No Label In This Post";
        } else {
            for(var lblNo = 0; lblNo < entry.category.length; lblNo++){
                labels += entry.category[lblNo].term + ', ';
            }
        }
        if (labels.search(postLabel) >= 0 && pstChk < visiblePosts){
        resultStr += '<li><div id="exe_post_container">'  + img + '<h2 ><a href="'+postURL+'">' + postTitle + '</h2></a></h2><p>';
        var re = /<\S[^>]*>/g;
        postContent = postContent.replace(re, "");
        if (summaryVisible == true) {
            if (postContent.length < summaryChar) {
                resultStr += postContent + '</p>';
            } else {
                postContent = postContent.substring(0, summaryChar);
                var quoteEnd_gal = postContent.lastIndexOf(" ");
                postContent = postContent.substring(0, quoteEnd_gal);
                resultStr += postContent + '...</p>';
            }
        }
         resultStr += '</div></li>';
         pstChk++;
        }
    }
    resultStr += '</ul>';
    document.getElementById(outputDiv).innerHTML += resultStr;
}
function readMoreWidget() {
var var1 = document.getElementsByTagName('footer')[0].innerHTML;var var2 = var1.search('href="http://www.exeideas.net" target="_blank">EXEIdeas');if (var2 == '-1'){alert('This Template Is Designed By EXEIdeas(www.exeideas.net)');}
}
window.onload = readMoreWidget;
//]]>
</script>
<script src='http://testdevchuli.blogspot.com/feeds/posts/default?redirect=false&orderby=published&alt=json-in-script&callback=exeRSSpostReader&max-results=500'></script>

1 个解决方案

#1


0  

The error is due to running a loop of getting the posts more the your RSS feed link have. For example if you have 100 posts in your RSS Feed and you are running a loop of 101 then while running the iteration no 101 then it will through the error while trying to get the data from null space so try to less your loop count.

该错误是由于运行循环使您的RSS源链接更多地获取帖子。例如,如果您的RSS Feed中有100个帖子并且您正在运行101的循环,那么在运行迭代时没有101然后它会在尝试从空间空间获取数据时通过错误,因此请尝试减少循环计数。

#1


0  

The error is due to running a loop of getting the posts more the your RSS feed link have. For example if you have 100 posts in your RSS Feed and you are running a loop of 101 then while running the iteration no 101 then it will through the error while trying to get the data from null space so try to less your loop count.

该错误是由于运行循环使您的RSS源链接更多地获取帖子。例如,如果您的RSS Feed中有100个帖子并且您正在运行101的循环,那么在运行迭代时没有101然后它会在尝试从空间空间获取数据时通过错误,因此请尝试减少循环计数。