Blogger Javascript with JSON error on Posts > 500

前端 未结 4 1914
情歌与酒
情歌与酒 2021-01-03 11:52

I would like to show random posts to my blogger.

I got a javascript from googling and tried it, but the number of random posts are not correct (should be 10 but some

4条回答
  •  借酒劲吻你
    2021-01-03 12:02

    So it seems that the feed entry at the randomized index is null, in that case add another condition to ensure that every entry in randomized indexes is not null.

    Replace:

    if(flag==0&&l!=0){
    

    with:

    if(flag==0&&l!=0&&json.feed.entry[l-1]!=null){
      randarray[i++]=l;
    }
    

    I hope that solves your problem.

    Regards,

    PP

    EDIT: Then you can call the feed url twice, this is the quick and dirty way to achieve so:

    
    
    
    
    

提交回复
热议问题