实现ajax功能的js:
Home > Web Front-end > JS Tutorial > body text

RSS Reader code implemented using jQuery's ajax function_jquery

WBOY
Release: 2016-05-16 18:47:11
Original
1135 people have browsed it

Let’s take a look at the effect first:

First, an ascx page is needed to bind the content of the rss source to a ListView through an XDocument. The code is as follows:

Copy code The code is 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 The code is as follows:








  • <%# Eval("Title") %>

    <%# Eval( "Description") %>




  • Next you need to create an aspx page to Display RSS content. Of course, this page uses jQuery's AJAX to get the above data.
    HTML page code:
    RSS Reader code implemented using jQuery's ajax function_jquery
    JS to implement ajax function:
    Copy code The code is 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 is the content of the web service RSSReader.asmx:
    Copy code The code is 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();
    }
    }

    There is also an image used in the page, here it is No more uploading.
    Code download:
    http://xiazai.jb51.net/200909/yuanma/RSSREader.rar
    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!