asp.net Click to see more implementation of no refresh load implementation code _ Practical skills

Source: Internet
Author: User
The JS code for the page page is as follows,
Copy Code code as follows:

<script type= "Text/javascript" >
$ (function () {
function init (count, start) {
$.ajax ({
Type: "Get",
DataType: "JSON",
URL: "Handler/handler.ashx",
Data: {action: "Getmorenews", Count:count, Start:start},
Beforesend:function () {$ ("#divload"). Show (); $ ("#more2"). Hide ();
Complete:function () {$ ("#divload"). Hide (); $ ("#more2"). Show ();},
Success:function (JSON) {
var str = "";
$.each (JSON, function (index, array) {
var str = "<div class= ' Single_item ' >"
+ "<div class= ' Element_head ' >"
+ "<div class= ' author ' >" + array[' Title '] + "</div>"
+ "<div class= ' Date ' >" + array[' date ' + "</div>"
+ "</div>"
+ "<div class= ' content ' >" + array[' Contents '] + "</div>"
+ "</div>";
$ ("#more"). Append (str);
});
if (JSON = = "") {
$ ("#more2"). HTML ("No more content loaded ...");
}
}
});
}
var count = 5;
var start = 0;
Init (count, start);
$ (". Get_more"). Click (function () {
start = 5;
Init (count, start);
});
});
</script>

Explain the general meaning of the above JS: Define an Init method with two parameters count and Start,count mean to display the number of comments per load, start meaning, each time from the database read the location, such as 0,5,10.
The code for the Handler.ashx processing page is as follows
Copy Code code as follows:

The JS code for the page page is as follows,
<b> <script type= "Text/javascript" >
$ (function () {
function init (count, start) {
$.ajax ({
Type: "Get",
DataType: "JSON",
URL: "Handler/handler.ashx",
Data: {action: "Getmorenews", Count:count, Start:start},
Beforesend:function () {$ ("#divload"). Show (); $ ("#more2"). Hide ();
Complete:function () {$ ("#divload"). Hide (); $ ("#more2"). Show ();},
Success:function (JSON) {
var str = "";
$.each (JSON, function (index, array) {
var str = "<div class= ' Single_item ' >"
+ "<div class= ' Element_head ' >"
+ "<div class= ' author ' >" + array[' Title '] + "</div>"
+ "<div class= ' Date ' >" + array[' date ' + "</div>"
+ "</div>"
+ "<div class= ' content ' >" + array[' Contents '] + "</div>"
+ "</div>";
$ ("#more"). Append (str);
});
if (JSON = = "") {
$ ("#more2"). HTML ("No more content loaded ...");
}
}
});
}
var count = 5;
var start = 0;
Init (count, start);
$ (". Get_more"). Click (function () {
start = 5;
Init (count, start);
});
});
</script></b>
Explain the general meaning of the above JS: Define an Init method with two parameters count and Start,count mean to display the number of comments per load, start meaning, each time from the database read the location, such as 0,5,10.
The code for the Handler.ashx processing page is as follows
[Code]
Case "Getmorenews":
int count = Int. Parse (context. request.querystring["Count"]. ToString ());
int start = Int. Parse (context. request.querystring["Start". ToString ());
ilist<winenews> morenews = Winenewsmanager.winenewsqueryfrommton (Count,start);
Content = Javascriptconvert.serializeobject (morenews);
Break

The Winenewsqueryfrommton code is as follows
Copy Code code as follows:

public static ilist<winenews> Winenewsqueryfrommton (int count,int start)
{
using (SqlConnection cn = new SqlConnection (Sqlhelp.conn))
{
cn. Open ();
String sql = ' Select top ' + Count + ' f.* from Tb_winenews F WHERE-id not ' (SELECT top "+ start +" ID from tb_winenew s ORDER BY id desc DESC ";
SqlCommand cmd = new SqlCommand (SQL, CN);
SqlDataReader dr = cmd. ExecuteReader ();
ilist<winenews> list = new list<winenews> ();
while (Dr. Read ())
{
Winenews winenews = new Winenews ();
if (dr["ID"]!= DBNull.Value)
{
winenews.id = (int) dr["ID"];
}
if (dr["Title"]!= DBNull.Value)
{
Winenews.title = (string) dr["Title"];
}
if (dr["Contents"]!= DBNull.Value)
{
Winenews.contents = (string) dr["Contents"];
}
if (dr["picture"]!= DBNull.Value)
{
Winenews.picture = (string) dr["picture"];
}
if (dr["Date"]!= DBNull.Value)
{
Winenews.date = ((DateTime) dr["Date"). ToString ("Yyyy-mm-dd HH:mm:ss");
}
List. ADD (winenews);
}
Dr. Close ();
return list;
}
}

Operation effect is as follows

Author: Chen Sai

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.