首頁  >  文章  >  web前端  >  js使用ajax讀取部落格rss範例_基礎知識

js使用ajax讀取部落格rss範例_基礎知識

WBOY
WBOY原創
2016-05-16 16:49:461034瀏覽

複製程式碼 程式碼如下:

BR>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict 。 dtd">


這是測試


var xmlHttp;

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}

函數 readRSS(url) {
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

  
}

函數handleStateChange() {
    if(xmlHttp.readyState == 4) {
   if(xmlHttp.ready  4) {
  結果集();
        }
    }
}

function ResultSet() {
    var results = xmlHttp.responseXML;
    var title = null;
    var item = null;
    var link=null;
    //取得頻道
    var ccc=results.getElementsByTagName("channel");
     var headtitle=ccc[0].getElementsByTagName("title")[0].firstChild.nodeValue;
     var headlink=ccc[0].getElementsByTagName("link")[0].firstChild.nodeValue;
     var cell = document.createElement("div");
        cell.innerHTML="

"標題「


」;
        document.getElementById("結果").appendChild(cell);
       //取得items
    var items = results.getElementsByTagName("item");
    for(var i = 0; i         item = items[i];
        link=item.getElementsByTagName("link")[0].firstChild.nodeValue;
        title = item.getElementsByTagName("title")[0].firstChild.nodeValue;
        var cell = document.createElement("div");
        cell.innerHTML=""標題「
」;
       document.getElementById("結果").appendChild(cell);
    }

}
function readrss1()
{
    var url=document.getElementById("txturl").value;
    if(url=="")
    {
       alert("請輸入RSS位址");
        }
    else
        {
      
            }
    }

腳本>
頭>


 

ajax讀取rss範例


 


  blogjava新手區      
   blogblogjava新手區    
   
blogjava非技術區
    
綜合區

 
    輸入RSS位址:


 

   


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn