Sometimes, your Blog may need the following features:
Aggregates and displays the latest Blog articles on your own Blog, so that you can learn about your friends in a timely manner. In addition, it is also convenient for visitors to find Blog and articles related to this blog.
This function can be called "Blog aggregation" or "Blog broadcast". Currently, software or services that implement this function have restrictions: for example, although Terac Sinfonia, Lilina, and MXNA have powerful functions, they must be installed and cannot be customized or embedded in the Blog sidebar. On the other hand, BSP currently providing such services can only aggregate users in the system, and there are many restrictions.
To solve the above problems, I used AJAX (Asynchronous JavaScript + XML) technology to achieve the function of aggregating and displaying the latest articles on my Blog. You can, as needed, for customization. By default, the RSS 2.0 standard is supported, which is used by Terac Miracle, Movable Type, Word Press, Donews, blog Park, and CSDN. the Text system supports RSS 0.92, RSS 1.0, and Atom 0.3.
Why AJAX? First, aggregating others' RSS cannot affect the speed of your website, so asynchronous execution is required. Secondly, RSS itself is a very standard XML document. In addition, because the size of the aggregated content is not determined, therefore, local refresh is required. The most important thing is to use AJAX to completely store the XML loading and parsing operations on the client for processing, saving the server bandwidth and resources. Finally, this function is fully implemented using JavaScript. In this way, no matter whether your blog is ASP or ,. net, PHP, JSP, Perl, and even pure HTML. The usage is as follows:
First, add the following code to the sidebar of your Blog:
Copy codeThe Code is as follows:
<Script src = "ajax_rss.js" type = "text/javascript"> </script>
Then, save the following content as "ajax_rss.js" and upload it to the corresponding server location:
Copy codeThe Code is as follows:
// You can add RSS 2.0 compliant
ProcessRSS ('HTTP: // www.songlian.cn/blog/feed.php ');
ProcessRSS ('HTTP: // www.bo-blog.com/weblog/feed.php ');
Function processRSS (url ){
Var req = getXMLHttpRequest ();
Req. onreadystatechange = function (){
If (req. readyState = 4 & req. status = 200 ){
Var doc=req.responseXML.doc umentElement;
ParseRSS (doc );
}
}
Req. open ("GET", url, true );
Req. send (null );
}
Function parseRSS (doc ){
// If you want to use RSS 0.92, RSS 1.0, and Atom 0.3, You need to modify the following three lines:
Var blogName = doc. getElementsByTagName ("title") [0]. firstChild. data;
Var entryName = doc. getElementsByTagName ("title") [1]. firstChild. data;
Var entryLink = doc. getElementsByTagName ("link") [1]. firstChild. data;
Document. getElementById ('ajax _ rss '). innerHTML + = '<a target = "_ blank" href = "' + entryLink + '" title = "' + blogName + '">' + entryName + '</a> <br/> ';}
Function getXMLHttpRequest (){
Var xmlhttp;
Try {
Xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){
Xmlhttp = false;
}
}
If (! Xmlhttp & typeof XMLHttpRequest! = 'Undefined '){
Xmlhttp = new XMLHttpRequest ();
}
Return xmlhttp;
}
Now, the installation is complete. Test it!