mahmmoudeid
mahmmoudeid

Reputation: 29

TypeError: entry is undefined

What is the problem with this error

TypeError: entry is undefined

This error appears in the Firefox browser

<script type='text/javascript'>
  //<![CDATA[
  function showlatestpostswiththumbs(json) {
    document.write('<div class="terbaru">');
    for (var i = 0; i < posts_no; i++) {
      var entry = json.feed.entry[i];
      var posttitle = entry.title.$t;
      var postsurl;
      if (i == json.feed.entry.length) break;
      for (var k = 0; k < entry.link.length; k++) {
        if (entry.link[k].rel == 'replies' && entry.link[k].type == 'text/html') {
          var commentstext = entry.link[k].title;
          var commentsurl = entry.link[k].href;
        }
        if (entry.link[k].rel == 'alternate') {
          postsurl = entry.link[k].href;
          break;
        }
      }
      var recenthumb;
      try {
        recenthumb = entry.media$postImageUrl.url;
      } catch (error) {
        s = entry.content.$t;
        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 != "")) {
          recenthumb = d;
        } else recenthumb = 'https://2.bp.blogspot.com/-C3Mo0iKKiSw/VGdK808U7rI/AAAAAAAAAmI/W7Ae_dsEVAE/s1600/no-thumb.png';
      }
      document.write('<div class="mas-elemen">');
      document.write('<a href="' + postsurl + '"><img src="' + recenthumb + '"/></a>');
      document.write('<h6><a href="' + postsurl + '" target ="_top">' + posttitle + '</a></h6>');
      document.write('</div>');
    }
    document.write('</div>');
  }
  //]]>
</script>
<script style='text/javascript'>
  var posts_no = 10;
  var showpoststhumbs = true;
  var readmorelink = true;
</script>
<script src="/feeds/posts/default/?orderby=published&alt=json-in-script&callback=showlatestpostswiththumbs"></script>

Upvotes: 0

Views: 422

Answers (1)

Ananthakrishnan Baji
Ananthakrishnan Baji

Reputation: 1290

This error is causing because of this line

var entry = json.feed.entry[i];

because the json you passed into the function showlatestpostswiththumbs doesn't have a value at json.feed.entry[i], so entry is now undefined, please give correct json into that function (showlatestpostswiththumbs), thats all I can give with the info from your question

Upvotes: 1

Related Questions