Return to Snippet

Revision: 11853
at February 22, 2009 14:40 by chrisaiv


Initial Code
function SendAjax(url, callbackFunction) {
   if (window.XMLHttpRequest) {
      var request = new XMLHttpRequest();
   } else {
      var request = new ActiveXObject("Microsoft.XMLHTTP");
   }
 
   request.open("POST", url, true);
   request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
 
   request.onreadystatechange = function() {
      if (request.readyState == 4 && request.status == 200) {
         if (request.responseText) {
            ReceiveAjax(request.responseText, callbackFunction);
         }
      }
   }

   request.send(null);
}

function ReceiveAjax(response, callbackFunction) {
   if (window.ActiveXObject) {
      var doc = new ActiveXObject("Microsoft.XMLDOM");
      doc.async = "false";
      doc.loadXML(response);
   } else {
      var parser = new DOMParser();
      var doc = parser.parseFromString(response,"text/xml");
   }

   callbackFunction(doc.documentElement);
}

function ValueFromTagName(item, tagname) {
   var val = item.getElementsByTagName(tagname);
   return val[0].firstChild.nodeValue;
}

function ParseData(data) {
   var items = data.getElementsByTagName('item');
   var output = '<ul>';

   for (var i = 0; i < items.length; ++i) {
      var title = ValueFromTagName(items[i], 'title');
      var link = ValueFromTagName(items[i], 'link');

      output += '<li><strong><a href ="' + link + '">' + title + '</strong> ' + '</li>';
   }

   output += '</ul>';

   var RSSOutput = document.getElementById('RSSOutput');
   	   RSSOutput.innerHTML = output;
}

function LoadFeed( url ) {
   var GetFeed = url;
   SendAjax('getfeed.php?url=' + escape(GetFeed.value), ParseData);
}
LoadFeed( "http://del.icio.us/rss/twelvetone" );

Initial URL

                                

Initial Description
Simple Javascript that will get a feed and parse it using Ajax

Initial Title
JS: Parse RSS Feed

Initial Tags
js

Initial Language
JavaScript