1. html page:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> Weibo style 1 </title>
</Head>
<SCRIPT type = "text/JavaScript">
VaR XMLHTTP;
Function createxmlhttprequest ()
{
If (window. activexobject)
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest)
{
XMLHTTP = new XMLHttpRequest ();
}
}
Function addnumber ()
{
Createxmlhttprequest ();
// Var url = "ajaxmicrobloggingpaging. aspx? Num1 = "+ document. getelementbyid (" num1 "). Value +" & num2 = "+ document. getelementbyid (" num2 "). value;
VaR url = "handler. ashx ";
XMLHTTP. Open ("get", URL, true );
XMLHTTP. onreadystatechange = showresult;
XMLHTTP. Send (null );
}
Function showresult ()
{
If (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200)
{
Document. getelementbyid ("MList"). innerhtml = XMLHTTP. responsetext;
}
}
}
</SCRIPT>
<Body>
<Div class = "content" id = "MList"> </div>
<Input type = "button" name = "fdfds" value = "calculation" onclick = "addnumber ();"/>
</Body>
</Html>
2. dynamic page
<% @ Webhandler Language = "C #" class = "handler" %>
Using system;
Using system. Web;
Using system. text;
Using system. Data;
public class handler: ihttphandler {
Public void processrequest (httpcontext context) {
context. response. contenttype = "text/plain";
context. response. write (server_side_processing (5, 1);
}< br>
Public bool isreusable {
get {
return false;
}< BR >}
/// <Summary>
/// Server-side ProcessingProgramQuery data in the database and generate an XML file.
/// </Summary>
Public String server_side_processing (INT pagesize, int currentpage)
{
Stringbuilder resultxml = new stringbuilder ();
String str_xml;
Dataset Ds;
Dataaccess da;
Int I;
Resultxml. append ("<? XML version = '1. 0' encoding = 'gb2312 '?> ");
Resultxml. append ("<Ajax-response> \ n ");
Resultxml. append ("<root> \ n ");
Try
{
If (currentpage = 1)
{
Str_xml = "select top" + pagesize + "* From tbmicroblog order by microblogid DESC ";
}
Else
{
Str_xml = "select top" + pagesize + "* From tbmicroblog microblogid not in (select top" + pagesize * (currentpage-1) + "* From tbmicroblog order by microblogid DESC) where order by microblogid DESC ";
}
DA = new dataaccess ();
DS = da. getdatasetresult (str_xml, "xml_table ");
If (Ds! = NULL)
{
for (I = 0; I {< br> If (Ds. tables [0]. rows [I] = NULL)
{< br> break;
}
Resultxml. append ("<DATA> \ n ");
Resultxml. append ("\ t <microblogid>" + Ds. tables [0]. rows [I] ["microblogid"]. tostring () + "</microblogid> \ n ");
If (Ds. Tables [0]. Rows [I] ["userid"]. tostring (). Trim ()! = "")
{
Resultxml. append ("\ t <userid>" + httputility. urlencodeunicode (Ds. tables [0]. rows [I] ["userid"]. tostring (). trim () + "</userid> \ n ");
}
Else
{
Resultxml. append ("\ t <userid >#</userid> \ n ");
}
If (Ds. Tables [0]. Rows [I] ["content"]. tostring (). Trim ()! = "")
{
Resultxml. append ("\ t <content>" + httputility. urlencodeunicode (Ds. tables [0]. rows [I] ["content"]. tostring (). trim () + "</content> \ n ");
}
Else
{
Resultxml. append ("\ t <content >#</content> \ n ");
}
If (Ds. Tables [0]. Rows [I] ["pubdate"]. tostring (). Trim ()! = "")
{
Resultxml. append ("\ t <pubdate>" + httputility. urlencodeunicode (Ds. tables [0]. rows [I] ["pubdate"]. tostring (). trim () + "</pubdate> \ n ");
}
Else
{
Resultxml. append ("\ t <pubdate >#</pubdate> \ n ");
}
Resultxml. append ("</data> \ n ");
}
}
Else
{
Resultxml. append ("<DATA> \ n ");
Resultxml. append ("\ t <nodata>" + "no data! "+" </Nodata> \ n ");
Resultxml. append ("</data> \ n ");
}
}
Catch (exception E)
{
Console. writeline ("{0} exception caught.", e );
}
Resultxml. append ("</root> \ n ");
Resultxml. append ("</Ajax-response> ");
Return resultxml. tostring ();
}
}