AJAX preliminary application-code and download of RSS no-brush new aggregator page 1/3

Source: Internet
Author: User

Rss. js
Copy codeThe Code is as follows:
<! --
// Control ID
Function getId (objId ){
Return document. getElementById (objId)
}
// Link corresponding array, please indicate Reprinted from http://www.cnrui.cn/blog
Function urlArrary (urlName ){
Switch (urlName ){
Case "clear ":
Return "http://www.cnrui.cn/blog/feed.asp"
Case "a-fei ":
Return "http://www.a-fei.net/blog/rss.xml"
Case "ryanxia ":
Return "http://www.ryanxia.com/blog/feedrss2.asp"
Case "awflasher ":
Return "http://www.awflasher.com/blog/feed.asp"
Case "seles ":
Return "http://www.cnrui.cn/seles/feedrss2.asp"
Case "wawa ":
Return "http://a-fei.net/wawa/blog/rss2.php"
Case "dreammx ":
Return "http://www.dreammx.com/xhyl/feed.asp"
Default:
Return false
}
}
// Sidebar control, which must be reprinted from http://www.cnrui.cn/blog
Function closebar (targetid, objId ){
If (document. getElementById ){
Target = getId (targetid );
Objsty = getId (objId );
If (target. style. display = "none "){
Target. style. display = "";
Main. style. width = "800px ";
Objsty. innerHTML = "Close sidebar"
} Else {
Target. style. display = "none ";
Main. style. width = "100% ";
Objsty. innerHTML = "enable sidebar"
}
}
}
// The load is grayed out, indicating that it is reprinted from http://www.cnrui.cn/blog.
Function listen (){
GetId ("prolist"). className =;
}
Function btnSty (objId, objStyle)
{
GetId (objId). style. display = objStyle
}
// Prompt window control
Function ifodis (){
BtnSty ("loadifo", "none ");
}
Function settime (){
SetTimeout (a, 1000 );
}
Function loadtime (){
GetId ("loadifo"). innerHTML + = "."
}
// Data entry
Function ent (urlName ){
Window. location. hash = urlName
Var frmUrl = saveState (urlName); // write information to ifream
Var gamestart = loadrss (urlName); // AJAX Data Process
}
// XML Data Binding
Var xmldoc = false;
Function loadrss (urlName ){
Var myurl = urlArrary (urlName)
If (myurl ){
Listen ("mainbg2 ");
// Generate a random number and limit the number of refreshes
Var Num = Math. floor (Math. random () * 100 );
// Define the forward Parameters
Url = myurl + "? Id = "+ Num;
// Defined as asynchronous transmission mode
Xmldoc = false;
// The XMLHttp class that needs to be created when the browser such as Safari is killed
If (window. XMLHttpRequest ){
Xmldoc = new XMLHttpRequest ();
If (xmldoc. overrideMimeType ){
Xmldoc. overrideMimeType ('text/xml ');
}
}
// XMLHttp class created in IE browser
Else if (window. ActiveXObject ){
Try {
Xmldoc = new ActiveXObject ("Msxml3.XMLHTTP ");
}
Catch (e ){
Try {
Xmldoc = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e ){
Try {
Xmldoc = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (e ){}
}
}
}
// Return when the XMLHTTP class cannot be created
If (! Xmldoc ){
Return false;
}
// Call the CheckState Function
Xmldoc. onreadystatechange = CheckState;
Xmldoc. open ('get', url, true );
Xmldoc. send (null );
} Else {
GetId ("listnum"). innerHTML = "the address you entered is incorrect. Please try again! "
}
}
// Status detection
Function CheckState (){
Var response = xmldoc.responseXML.doc umentElement;
BtnSty ("loadifo", "block ")
// Receives the complete Server Response
If (xmldoc. readyState = 1 ){
GetId ("loadifo"). innerHTML = "connect to server"
}
Else if (xmldoc. readyState = 2 ){
GetId ("loadifo"). innerHTML = "start to load data"
}
Else if (xmldoc. readyState = 3 ){
GetId ("loadifo"). innerHTML = "loading data"
Settime (loadtime)
}
Else if (xmldoc. readyState = 4 ){
// The HTTP server response value is successful.
If (xmldoc. status = 200 ){
// Write the string returned by the server to the area where the ID is showdiv in the page.
GetId ("loadifo"). innerHTML = "loaded"
Settime (ifodis)
Num (response)
}
Else {
GetId ("loadifo"). innerHTML = "error" + xmldoc. status + "Click here to refresh ";
}
}
}
// Check Data Validity
Function trydata (nodeName, nodeName2 ){
Try {
Var nodeV = nodeName. firstChild. nodeValue;
} Catch (e ){
Try {
Var nodeV = nodeName2.firstChild. nodeValue;
} Catch (e ){
Var nodeV = "no available information"
}
}
Return nodeV;
}
// Total number of Record Sets
Function num (B ){
Try {
Var titleNode = B. selectNodes ("// rss/channel/title ");
Var a = B. getElementsByTagName ("item"). length
TitleV = trydata (titleNode (0 ));
GetId ("listnum"). innerHTML = "Total" + a + "Source:" + titleV;
Setlist (a, B );
} Catch (e ){}
}
If (top. location! = Self. location) top. location = self. location;


// Show the program list
// Defines the variables that receive node information pointing to each element.
Var titleNode, linkNode, categoryNameNode, authorNode, pubDateNode, descriptionNode
// Define the variable for receiving element values
Var titleV, linkV, categoryNameV, authorV, pubDateV, descriptionV
// Classification Aggregation
Function setlist (a, B)
{
Var prograNode = B. getElementsByTagName ("item ");
Var adminlinkNode = B. selectNodes ("// rss/channel/link ");
Var titleNode = B. selectNodes ("// rss/channel/item/title ");
Var linkNode = B. selectNodes ("// rss/channel/item/link ");
Var categoryNode = B. selectNodes ("// rss/channel/item/category ");
Var authorNode = B. selectNodes ("// rss/channel/item/author ");
Var pubDateNode = B. selectNodes ("// rss/channel/item/pubDate ");
Var descriptionNode = B. selectNodes ("// rss/channel/item/description ");
Var category2sNode = B. selectNodes ("// rss/channel/item/dc: subject ");
Var author2sNode = B. selectNodes ("// rss/channel/item/dc: creator ");
Var pubDate2sNode = B. selectNodes ("// rss/channel/item/dc: date ");
Var listchar = ""
// Use the for loop to generate list information
For (I = 0; I <a; I ++)
{
TitleV = trydata (titleNode (I ))
LinkV = trydata (linkNode (I ))
CategoryV = trydata (categoryNode (I), category2sNode (I ))
AuthorV = trydata (authorNode (I), author2sNode (I ))
PubDateV = trydata (pubDateNode (I), pubDate2sNode (I ))
DescriptionV = trydata (descriptionNode (I ))
AdminlinkV = trydata (adminlinkNode (0 ))
// Load the obtained element value to the string that generates the table
Listchar + = "}
// Output the generated table to the DIV element of the page
GetId ("prolist"). innerHTML = listchar;
Listen ("mainbg ")
}
// Browser rollback
// Rewrite the IFREAM link to focus the browser back
Function saveState (message ){
Var hisFrm = getId ("historyFrame ")
HisFrm. src = "blank.html? "+ Message
}
// Detect IFREAM
Window. dhtmlHistory = {
IframeLoaded: function (newLocation ){
Var hash = new String (newLocation. search)
If (hash. length> = 2 & hash. charAt (0) = "? "& Hash. substring (1 )! = DelChar ()){
Hash = hash. substring (1)
Window. location. hash = hash;
Var hisFrmdata = loadrss (hash)
}
}
}
// Link to the browser
// Remove the symbol. Please indicate http://www.cnrui.cn/blog
Function delChar (){
Var a = window. location. hash
Return a. substring (1)
}
Window. onload = function (){
If (window. location. hash. length> = 2 ){
Ent (delChar ())
}
}
// -->

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.