当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 使用jQuery的ajax功能实现的RSS Reader 代码

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 使用jQuery的ajax功能实现的RSS Reader 代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 490 ::
收藏到网摘: n/a

Rss阅读器挺不错的。我觉得如果在igoogle或是dropthings这种形式的portal下来放很多RSS模块显示自己每天需要关注的信息那将会减少大家很多的打开浏览器和输入网址的时间。

先看看效果来着:

首先需要一个ascx页面通过一个XDocument把rss源的内容绑定到一个ListView上。代码如下:

复制代码 代码如下:

protected void Page_Load(object sender, EventArgs e)
{
// For demo purposes.
System.Threading.Thread.Sleep(1000);
XDocument feedXML =
XDocument.Load("http://feeds.feedsky.com/csdn.net/dujingjing1230");
var feeds = from feed in feedXML.Descendants("item")
select new
{
Title = feed.Element("title").Value,
Link = feed.Element("link").Value,
Description = feed.Element("description").Value
};
PostList.DataSource = feeds;
PostList.DataBind();
}

复制代码 代码如下:

<asp:ListView runat="server" ID="PostList">
<LayoutTemplate>
<ul>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><a href='<%# Eval("Link") %>'><%# Eval("Title") %></a><br />
<%# Eval("Description") %>
</li>
</ItemTemplate>
</asp:ListView>

接下来需要创建一个aspx页面来显示RSS内容,当然这个页面中就使用了jQuery的AJAX来得到上面的数据。
HTML页面代码:

实现ajax功能的js:
复制代码 代码如下:

$(document).ready(function() {
$.ajax({
type: "POST",
url: "RSSReader.asmx/GetRSSReader",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$('#RSSContent').removeClass('loading');
$('#RSSContent').html(msg.d);
}
});
});

最后是RSSReader.asmx这个web Services的内容:
复制代码 代码如下:

public class RSSReader : System.Web.Services.WebService {
[WebMethod]
public string GetRSSReader()
{
Page page = new Page();
UserControl ctl =
(UserControl)page.LoadControl("~/RSSReaderControl.ascx");
page.Controls.Add(ctl);
StringWriter writer = new StringWriter();
HttpContext.Current.Server.Execute(page, writer, false);
return writer.ToString();
}
}

页面中还有用到一个图片这里就不上传了。
代码下载:
/upload/tech/20091012/20091012100551_357a6fdf7642bf815a88822c447d9dc4.rar