RSS Reader code _jquery using jquery AJAX functionality

Source: Internet
Author: User

Look at the effect first:

First you need an ascx page to bind the content of the RSS feed to a ListView through a XDocument. The code is as follows:

Copy Code code as follows:

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 ();
}

Copy Code code as follows:

<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>

Next you need to create an ASPX page to display the RSS content, and of course this page uses jquery ajax to get the data.
HTML page code:

AJAX functionality to achieve the JS:
Copy Code code as follows:

$ (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);
}
});
});

Finally, the content of this Web services is rssreader.asmx:
Copy Code code as follows:

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 ();
}
}

The page is also useful to a picture is not uploaded here.
Code Download:
Http://xiazai.jb51.net/200909/yuanma/RSSREader.rar

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.