2017-09-04 129 views
0

這有什麼錯誤的問題出現在Firefox瀏覽器類型錯誤:條目未定義

TypeError: entry is undefined

此錯誤

<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> 
+0

我得到這個錯誤while run snippet「」message「:」未捕獲的SyntaxError:意外的令牌<「」 –

回答

1

此錯誤是因爲該行造成

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

因爲你傳遞給函數的json showlatestpostswiththumbs在json.feed.entry [i]沒有價值,所以入口現在是不確定的,請給正確的json到該函數(showlatestpostswiththumbs),這就是我所能給你的信息從你的問題

+1

掃描未捕獲的TypeError時出現此錯誤:無法讀取undefined的屬性'title' – mahmmoudeid

+1

我使用博主作者: – mahmmoudeid

+0

調用showlatestpostswiththumbs之前的Console.log (json),並看到它的結構 –