Use AJAX technology to aggregate on your blog and display the latest articles from a friend's blog (via RSS)

Source: Internet
Author: User
Tags movable type

Sometimes, your blog may need such a feature:

In their blog on the aggregation and display of Friends blog The latest article, so convenient for their timely understanding of friends, in addition, also facilitate visitors to find and this blog related blogs and articles.

This function you can call it "blog aggregation" or "blog network", at present, to achieve such a function of the software or services are limited: for example, Terac Sinfonia, Lilina, Mxna Although the function is very powerful, but need to install, can not be freely customized, Cannot embed in the blog sidebar. On the other hand, the BSP currently providing such services can only aggregate users within the system, with a lot of restrictions.

To solve the above problem, I used Ajax (asynchronous JavaScript + XML) technology to achieve a blog on their own to aggregate and display a friend blog The latest article features, you can, as required, free customization. The default is to support the RSS 2.0 specification, Terac Miracle, movable Type, Word Press, donews/Blog Park/csdn. Text system can be very good support, you can modify, to support RSS 0.92, RSS 1.0, Atom 0.3. The display effect can see my blog in the lower right corner of the "Friends of the latest blog."

Why use Ajax? First of all, the aggregation of other people's RSS can not affect the speed of their own site, so need asynchronous execution, second, RSS itself is a very normative XML document, in addition, because the aggregation content size is not set, so must be local refresh, the most important point, Using AJAX to completely load parse XML operations to the client to process, save server bandwidth and resources, and finally, this feature I completely with JavaScript implementation, so that no matter your blog is ASP,. Net, PHP, JSP, Perl, and even pure HTML can be used. Here is the usage:

First, add a piece of code to the appropriate location in your blog sidebar:

<script src= "Ajax_rss.js" type= "Text/javascript" ></script>

Then save the following to "Ajax_rss.js" (or download my ajax_rss.js directly), and upload it to the server at the appropriate location:

You are free to add RSS that conforms to the RSS 2.0 specification
Processrss (' Http://www.xintiantang.com/andy/index.xml ');
Processrss (' Http://www.xintiantang.com/joywave/index.xml ');
Processrss (' Http://www.xintiantang.com/skype/index.xml ');
Processrss (' http://www.donews.net/keso/rss.aspx ');
function Processrss (URL) {
var req = Getxmlhttprequest ();
Req.onreadystatechange = function () {
if (req.readystate = = 4 && req.status = 200) {
var doc=req.responsexml.documentelement;
parseRSS (DOC);
}
}
Req.open ("Get", url, True);
Req.send (NULL);
}
function parseRSS (DOC) {
If you want to use RSS 0.92, RSS 1.0, Atom 0.3, you need to change the following 3 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;
}

OK, the installation is over, test it. The display effect can see my blog in the lower right corner of the "Friends of the latest blog."

What needs to be explained is that because of the speed and the other server's reasons, Ajax can not guarantee that the RSS can be guaranteed, so sometimes may not be shown. In addition, it is recommended not to add too many blogs, because the load and resolution to the client, too much blog may cause the client's system to run slowly, or even the browser crashes.

Update: 2005/06/09 11:33

Due to security reasons, XMLHttpRequest can not cross domain, so can only aggregate current domain content, such as your blog in the new Paradise can only aggregate the new Paradise, blog in the blogosphere can only aggregate blog park, in fact, for some people, this is enough. I found the solution to cross domain problem: method one, using Apache mod_rewrite to rewrite other Domian's RSS cost, this need to configure the server, more cumbersome, not common. Method Two, with ASP,. Net, PHP, JSP, Perl, write a proxy script, I wrote JSP and PHP, later released. Other script is no way, if someone wrote it, send it to me, shared out:).

Update: 2005/06/09 17:40

In fact, this thing is suitable for the use of a small amount of blog, if you visit a large number of blog, Shun with a friend Blog RSS access is also very large, very wasteful friend blog server bandwidth ^_^. Of course, you can use Bloglines or FeedBurner relay, waste the devil's bandwidth to go: D.

As the warm fish said, it is best to provide such services, but I do too many things, I think in the ^_^. However, there are many issues to consider: Cache, aggregation frequency, aggregation efficiency, RSS storage, and so on, if you are doing this or want to be friends please consider these questions.

PHP code (saved into keso.php, I aggregated the keso, please don't be offended:).

Header ("Content-type:text/xml");
TODO should use cache
$rssData = file_get_contents ("http://www.donews.net/keso/rss.aspx");
Echo $rssData;
?>

Then upload it to the server and join the line in Ajax_rss.js: Processrss (' http://www.xintiantang.com/keso.php '), which solves the XMLHttpRequest cross Domain problem.

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.