$(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。
页面页面的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;
全部评论