Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use AJAX technology to aggregate and display the latest articles of my friend Blog on your own Blog

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use AJAX technology to aggregate and display the latest article of my friend Blog on my Blog. The article is very detailed and has a certain reference value. Interested friends must finish reading it!

Sometimes, your Blog may need this feature:

Aggregate and display the latest articles of my friend Blog on your own Blog, so that you can keep abreast of your friends' news. In addition, it is also convenient for visitors to find blog and articles related to this Blog.

You can call this function "Blog aggregation" or "Blog webcast". At present, the software or services that achieve this function are limited: for example, Terac Sinfonia, Lilina, and MXNA are all powerful, but they need to be installed, cannot be freely customized, and cannot be embedded in the Blog sidebar. On the other hand, at present, the BSP that provides such services can only aggregate users within the system, and there are many restrictions.

In order to solve the above problems, I use AJAX (Asynchronous JavaScript + XML) technology to aggregate and display the latest articles of my friend Blog on my Blog, which you can customize freely according to your needs. RSS 2.0 specification is supported by default, and .Text systems adopted by Terac Miracle, Movable Type, Word Press, Donews / blog Park / CSDN are well supported. You are free to modify to support RSS 0.92, RSS 1.0, Atom 0.3.

Why use AJAX? First of all, aggregating other people's RSS can not affect the speed of your own website, so it needs to be executed asynchronously. Secondly, RSS itself is a very standard XML document. In addition, because the size of the aggregate content is uncertain, it must be partially refreshed. Most importantly, using AJAX to completely load and parse the XML operation to the client for processing, saving server bandwidth and resources. Finally, I completely implemented this function in JavaScript. This way, it doesn't matter if your blog is ASP, .net, PHP, JSP, Perl, or even pure HTML. The usage is as follows:

First, add this code in the right place in your Blog sidebar:

The code is as follows:

Then save the following as "ajax_rss.js" and upload it to the appropriate location on the server:

The code is as follows:

/ / you are free to add RSS that conforms to the RSS 2.0 specification.

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.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 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') [xss_clean] + =''+ entryName+'';}

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

}

The above is all the contents of the article "how to use AJAX technology to aggregate and display the latest articles of my friend Blog on your Blog". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report