Blogger Recent Posts using jQuery Ajax and atom feed

31.8.10
I just tried to parse the rss feed using jquery and ajax, but had some parse error doing so, but anyway I did the job using atom feed instead of rss2. Here is the javascript  code I used to inject the code  into My site.



$.ajax({
  type: "GET",
  url: "xml/atom.xml",
  contentType:'application/xml',
  dataType: ($.browser.msie) ? "text" : "xml",
  success: parseXml
});
function parseXml(d){
 if (jQuery.browser.msie) {
  var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.loadXML(xml);
  xml = xmlDoc;
 }
 var i=0;
 $(d).find("entry").each(function()
  {
   if(i++ <6) {
     var title=document.createElement('a');
     title.setAttribute('target','_blank');     
     title.setAttribute('href',$(this).find('link[rel="alternate"]').attr('href'));
     title.innerHTML=$(this).find('title').text();
     var desc =document.createElement('p');
     desc.innerHTML=$(this).find('summary').text().substring(0,100);
     var item=document.createElement('div');
     item.setAttribute('class','post');
     item.appendChild(title);
     item.appendChild(desc);
     $('#blog-posts').append(item);
  }
}

This code injects post-links + short description into div with id 'blog-posts'.

Related Posts by Categories



Widget by Hoctro | Jack Book

0 Responses: