Use AJAX to get an RSS Feed | Language: | Client Side - JavaScript | Author: | Jon Lokken | Date: | 2-26-2008 | |
| Description: | View Example | This show how you can use AJAX to retrieve an RSS feed from an ASP page. This page shows the client page JavaScript portion with cross browser compatibility. |
<html> <head> <script type="text/javascript"> function ajaxFunction() { document.getElementById("time2").innerHTML="Getting Yahoo RSS Feed Now..."; var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); //alert("You are using IE 7.0, Firefox, Opera 8.0+, or Safari!"); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); //alert("You are using IE 6.0 +with MSXML12.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); //alert("You are using IE 5.5+ with XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } }
xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4){ //document.myForm.time.value=xmlHttp.responseText; document.getElementById("time2").innerHTML=xmlHttp.responseText; } /* * 0=The request is not initialized * 1=The request has been set up * 2=The request has been sent * 3=The request is in process * 4=The time request is complete */ }
xmlHttp.open("GET","ajaxrss.asp",true); xmlHttp.send(null); } </script> </head>
<body> <form name="myForm"> <input type="button" value="Get RSS Feed >>" name="B1" onclick="ajaxFunction();"></form> <span id="time2"></span> </body> </html>
Disclaimer: | Feel free to use this code I have written. I take no responsibility for this code working, imply no warranty as to it's validity, and will not be held liable if you decide to try it. I am only trying to help out others so they don't have to struggle with the same problems as me... | |