Home » , , , , , » JSON Blogger dengan Ajax JQuery

JSON Blogger dengan Ajax JQuery

HTML

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

JQuery

// $.ajax({url:feedUrl,type:'get',dataType:'jsonp',success:function(json){ ... }});
$(function() {
$.ajax({
url: 'http://hompimpaalaihumgambreng.blogspot.com/feeds/posts/summary?alt=json-in-script',
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;
break;
}
}
skeleton += '<li><a href="' + link + '">' + title + '</a></li>';
}
skeleton += '</ol>';
$('#result').html(skeleton);
} else {
$('#result').html('<span>No result!</span>');
}
},
error: function() {
$('#result').html('<strong>Error Loading Feed!</strong>');
}
});
});

0 komentar:

Posting Komentar