Sabtu, 13 Oktober 2012

JavaScript Feed Json Blogger/Blogspot

Berikut ini kode parsing feed json blogspot dengan menggunakan javascript.

<h3>Allpost</h3>
<div id="allpost"></div>
<script>
function allpost(root) {
    var feed = root.feed;
    var entries = feed.entry || [];
    var dimension = 90;
    var html = ['<ul>'];

    for (var i = 0; i < entries.length; ++i) {
      var entry = entries[i];
      var title = (entry.title.type == 'text') ? entry.title.$t : escape(entry.title.$t);
      var link = (entry['link']) ? entry['link'][4].href : "";
      var summary = (entry.summary.type == 'text') ? entry.summary.$t : escape(entry.summary.$t);
      var thumbnail = (entry.media$thumbnail) ? entry.media$thumbnail.url : "";
      var thumbnails = thumbnail.replace(/s\B\d{3,4}/,'s' + dimension);
      html.push('<li><img style="float:left;margin:0 5px 5px 0" src="',thumbnail,'"><a href="', link, '">', title, '</a><br>',summary,'</li>');
    }
    var linkprev = feed.link[4].href;
    var linknext = feed.link[5].href;
    html.push('',linknext,'<br>',linkprev,'');
    html.push('</ul>');
    document.getElementById("allpost").innerHTML = html.join("");
  }
</script>
<script src="http://www.yourblog.blogspot.com/feeds/posts/default?max-results=9999&alt=json-in-script&callback=allpost"></script>

Ganti www.yourblog.blogspot.com dengan url blog Anda.
  Share

1 komentar:

  1. kita juga punya nih artikel mengenai java script, berikut linknya semoga bermanfaat ya :D
    http://repository.gunadarma.ac.id/bitstream/123456789/2371/1/02-02-011.pdf

    BalasHapus