HTML如何实现查看更多的,asp.net点击 查看更多 实现无刷新加载的实现代码

页面页面的js代码如下,

$(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 = "

"

+ "

"

+ "

" + array['Title'] +"
"

+ "

" + array['Date'] + "
"

+ "

"

+ "

" + array['Contents'] + "
"

+ "

";

$("#more").append(str);

});

if (json == "") {

$("#more2").html("没有更多内容加载了……");

}

}

});

}

var count = 5;

var start = 0;

init(count, start);

$(".get_more").click(function () {

start += 5;

init(count, start);

});

});

解释上面js的大体意思:定义一个init方法,此方法带有两个参数count和start,count意思是每次加载显示评论数,start意思是,每次从数据库中读取的位置,比如0,5,10。

Handler.ashx处理页面的代码如下

页面页面的js代码如下,

$(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 = "

"

+ "

"

+ "

" + array['Title'] +"
"

+ "

" + array['Date'] + "
"

+ "

"

+ "

" + array['Contents'] + "
"

+ "

";

$("#more").append(str);

});

if (json == "") {

$("#more2").html("没有更多内容加载了……");

}

}

});

}

var count = 5;

var start = 0;

init(count, start);

$(".get_more").click(function () {

start += 5;

init(count, start);

});

});

解释上面js的大体意思:定义一个init方法,此方法带有两个参数count和start,count意思是每次加载显示评论数,start意思是,每次从数据库中读取的位置,比如0,5,10。

Handler.ashx处理页面的代码如下

[code]

case "GetMoreNews":

int count = int.Parse(context.Request.QueryString["count"].ToString());

int start = int.Parse(context.Request.QueryString["start"].ToString());

IList morenews = WineNewsManager.WineNewsQueryFromMToN(count,start);

Content = JavaScriptConvert.SerializeObject(morenews);

break;

WineNewsQueryFromMToN代码如下

public static IList 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 IN (SELECT TOP " + start + " Id FROM tb_WineNews ORDER BY Id desc) ORDER BY Id desc";

SqlCommand cmd = new SqlCommand(sql, cn);

SqlDataReader dr = cmd.ExecuteReader();

IList list = new List();

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;

}

}

运行效果如下

d32915aba3088d07a4cf156a49df3cba.gif

作者:陈赛

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值