日期:2014-05-16 浏览次数:20697 次
<html> <head> <script language="javascript" src="rssd.js"> </script> </head> <style type="text/css"> .title{ font:16px bold helvetica,arial,sans-serif; padding:0px 30px 0px 30px; text-decoration:underline; } </style> <body> <h3>An Ajax RSS Reader</h3> <form name="form1"> URL of Rss feed:<input type="text" name="feed" size="50" value="http://"> <input type="button" value="Get Feed" onclick="getRSS()"><br> <div id="news"><h4>Feed Titles</h4></div> </form> </body> </html>
function getXMLHTTPRequest(){ var request=false; try{ request=new XMLHttpRequest(); } catch(err1) { try{ request=new ActiveXObject("Msxml2.XMLHTTP"); } catch(err2) { try{ request=new ActiveXObject("Microsoft.XMLHTTP"); } catch(err3) { request=false; } } } return request; } var http=getXMLHTTPRequest(); function getRSS(){ var myurl='rssproxy.php?feed='; var myfeed=document.form1.feed.value; myRand=parseInt(Math.random()*999999999); var modurl=myurl+escape(myfeed)+"&rand="+myRand; http.open("GET",modurl,true); http.onreadystatechange=useHttpResponse; http.send(null); } function useHttpResponse(){ if(http.readyState==4){ if(http.status==200){ /* alert("The server said:"+http.responseText); }else{ alert("An error has occurred:"+http.statusText); } } }*/ while(document.getElementById('news').hasChildNodes()) { document.getElementById('news').removeChild(document.getElementById('news').firstChild); } var titleNodes=http.responseXML.getElementsByTagName("title"); var descriptionNodes=http.responseXML.getElementsByTagName("description"); var linkNodes=http.responseXML.getElementsByTagName("link"); for(var i=1;i<titleNodes.length;i++) { var newtext=document.createTextNode(titleNodes[i].childNodes[0].nodeValue); var newpara=document.createElement('p'); var para=document.getElementById('news').appendChild(newpara); newpara.appendChild(newtext); newpara.className="title"; var newtext2=document.createTextNode(descriptionNodes[i].childNodes[0].nodeValue); var newpara2=document.createElement('p'); var para2=document.getElementById('news').appendChild(newpara2); newpara2.appendChild(newtext2); newpara2.className="descrip"; var newtext3=document.createTextNode(linkNodes[i].childNodes[0].nodeValue); var newpara3=document.createElement('p'); var para3=docuement.getElementById('news').appendChild(newpara3); newpara3.appendChild(newtext3); newpara3.className="link"; } } } }
<?php $mysession=curl_init($_GET['feed']); curl_setopt($mysession,CURLOPT_HEADER,false); curl_setopt($mysession,CURLOPT_RETURNTRANSFER,true); $out=curl_exec($mysession); header('Content-Type:text/xml'); echo $out; curl_close($mysession); ?>