Mecha versi 2.6.4 sudah dirilis!

JSON Blogger dengan AJAX jQuery

Tabel Konten
  1. HTML 
  2. jQuery 


<div id="result">Loading...</div>


// $.ajax({url:feedUrl,type:'get',dataType:'jsonp',success:function(json){ … }});
$(function() {
        url: '',
        type: 'get',
        dataType: 'jsonp',
        success: function(data) {
            var link, title, skeleton = '',
                content = data.feed.entry;
            if (content !== undefined) {
                skeleton = "<ol>";
                for (var i = 0; i < content.length; i++) {
                    title = content[i].title.$t;
                    for (var j = 0; j < content[i].link.length; j++) {
                        if (content[i].link[j].rel == "alternate") {
                            link = content[i].link[j].href;
                    skeleton += '<li><a href="' + link + '">' + title + '</a></li>';
                skeleton += '</ol>';
            } else {
                $('#result').html('<span>No result!</span>');
        error: function() {
            $('#result').html('<strong>Error loading feed!</strong>');

Lihat Demo

Referensi: Blogger JSON Feed With jQuery Ajax

21 Komentar


Thank you for give link of as original posts.

Taufik Nurrohman

Always. This site is purely for storing information that can be accounted for :)


Mas mau nanya nih seputar JSON Blogger..
klo misalnya ada post yang gambarnya disimpan bukan diblogspot/picasa misalnya pada photobucket, apa gambarnya bisa dipanggil lewat JSON feed??
karena saya ada script Random post kayak gini..

<script type="text/javascript">
var randarray = new Array();
var l = 0;
var flag;
var numofpost = 9;
var rd_monthNames  = ["January","February","March","April","May","June","July","August","September","October","November","December"];
function randomposts(r){var h=parseInt(r.feed.openSearch$totalResults.$t,10);for(i=0;i<numofpost;){flag=0;randarray.length=numofpost;l=Math.floor(Math.random()*h);for(j in randarray){if(l==randarray[j]){flag=1}}if(flag==0&&l!=0){randarray[i++]=l}}document.write('<ul id="randompostx">');for(n in randarray){var c=randarray[n];var m=r.feed.entry[c-1];var[0].name.$t,q=m.published.$t.substring(0,10),s=q.substring(0,4),g=q.substring(5,7),o=q.substring(8,10),f=m.thr$total.$t,e;if("media$thumbnail" in m){$thumbnail.url}else{e=""}for(k=0;k<;k++){if([k].rel=="alternate"){var[k].href,d=m.title.$t;break}}document.write('<li class="isobrick" >');document.write('<a href="'+a+'"><div class="overlayx"></div><img src="'+e+'"/></a>');document.write('<a href="'+a+'"><h5>'+d+"</h5></a>");document.write('<div class="inforp"><span class="dt">'+o+" "+rd_monthNames[parseInt(g,10)-1]+" "+s+'</span><span class="auty">'+b+'</span><span class="jkmt">'+f+'</span></div>');document.write('</li>')}document.write('</ul>')};
<script src="/feeds/posts/default?alt=json-in-script&start-index=1&max-results=1000&callback=randomposts" type="text/javascript"></script>

klo di blog yang saya pake berjalan dengan sukses..
tapi kadang ada blog yang error klo pake script ini..

apa masalahnya yah mas..
tolong dibantu.. :)

Terima kasih sebelumnya..

Taufik Nurrohman

Kalau file tidak diupload secara langsung tidak akan tampil sebagai thumbnail. Error mungkin muncul dari pengaturan feed blog yang dipotong.


"pengaturan feed blog yang dipotong" apa maksudnya mas??

apa yang dibagian setting --> site feednya??
yang full,until jump break, short..
apa yang itu mas??
apa sudah benar script random post diatas mas??
ato masih ada kodenya yang salah??

Taufik Nurrohman

Yap. Lebih baik disetting ke Penuh. Script sudah Saya coba dan baik-baik saja.


Thank you for you tutorial.


I changed the code to gave the ability to user to choose the label that he wanted to get posts from, The code work great if the user choose an English label (Ex : Sport), But the problem is when the user choose an Arabic label (Ex : رياضة) the code worked in all browser except IE (I have IE 9).
Do you have any idea about this issue.

Thank you again.

Taufik Nurrohman

What about encodeURIComponent ?





I use it like that but it didn't work.

$.ajax({url:""+window.location.protocol+"//""/feeds/posts/default/-/"+encodeURIComponent ('Label')+"?alt=json-in-script&max-results=5",type:'get',dataType:"jsonp",success:function(data){}

Taufik Nurrohman

var Label = 'رياضة';
url: window.location.protocol + '//' + + '/feeds/posts/default/-/' + encodeURIComponent(Label) + '?alt=json-in-script&max-results=5'


it worked if I add the label manually but when I get label like this it didn't work.

$('#home-layout .widget-content').each(function () {
var c = $(this).html(),
sp = c.split('/');
$(this).html("" + sp[0] + "" + sp[1] + "" + sp[2] + "");
var spc = $(this).text();
var pn = $(this).find("strong").eq(0).text(),
ps = $(this).find("strong").eq(1).text(),
pl = $(this).find("strong").eq(2).text();
var label = pl;

The user enter code like this 5/one/أخبار
5 : posts number.
one : posts style.
أخبار : The label.


The forth line should appear like this

$(this).html("" + sp[0] + "" + sp[1] + "" + sp[2] + "");

Taufik Nurrohman

Do you have any working example? JSFiddle, JSBin, etc?

Why don’t you just use this:

var pn = sp[0],
ps = sp[1],
pl = sp[2];

أسامة بويردن

Hi, Thanks for this tutorial but please can you tell me how to use ajax json to get the thumbnail from blogger posts? I try this but it's doesn't working at all :(
For Example :
var thumb = data.feed.entry[i].media$thumbnail.url;
htmlcode +='<img src="'+thumb+'"/>';

Can you tell me what is the problem here, Cheers!

Taufik Nurrohman

The feed data is now connected to content[i] not data.feed.entry[i] so:

var thumb = 'media$thumbnail' in content[i] ? '<img src="' + content[i].media$thumbnail.url + '">' : "";


أسامة بويردن

Thank you so much is working fine now :-bd
Demo :
Some templates have recent posts by add only recentposts on HTML/JAVASCRIPT widget without add <div id="recentposts"></div> How i can do that?

Taufik Nurrohman

They usually use document.write to output the generated HTML directly, but now it’s no longer recommended for this reason.

Komentar telah ditutup.