Aggregate RSS with Ajax technology

Source: Internet
Author: User
Tags movable type

Sometimes, your blog may need the following features:

Aggregate and display the latest blogs of friends on your own blogArticleIn this way, you can learn about your friends' messages in a timely manner. In addition, you can also find the blogs 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 such a segment to the sidebar of your blog.Code: <SCRIPT src = "ajax_rss.js" type = "text/JavaScript"> </SCRIPT>

Save the following content as "ajax_rss.js" and upload it to the corresponding server location: // You can freely add RSS 2.0 compliant with the RSS specifications.
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!

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.