asp.net点击 查看更多 实现无刷新加载的实现代码
网络编程 2021-07-04 22:40www.168986.cn编程入门
asp.点击 查看更多 实现无刷新加载的实现代码,需要的朋友可以参考下
页面页面的js代码如下,
<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(); },
plete: function () { $("#divload").hide(); $("#more2").show(); },
suess: 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("没有更多内容加载了……");
}
}
});
}
var count = 5;
var start = 0;
init(count, start);
$(".get_more").click(function () {
start += 5;
init(count, start);
});
});
</script>
解释上面js的大体意思定义一个init方法,此方法带有两个参数count和start,count意思是每次加载显示评论数,start意思是,每次从数据库中读取的位置,比如0,5,10。
Handler.ashx处理页面的代码如下
页面页面的js代码如下,
<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(); },
plete: function () { $("#divload").hide(); $("#more2").show(); },
suess: 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("没有更多内容加载了……");
}
}
});
}
var count = 5;
var start = 0;
init(count, start);
$(".get_more").click(function () {
start += 5;
init(count, start);
});
});
</script></b>
解释上面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<WineNews> morenews = WineNewsManager.WineNewsQueryFromMToN(count,start);
Content = JavaScriptConvert.SerializeObject(morenews);
break;
WineNewsQueryFromMToN代码如下
public static IList<WineNews> WineNewsQueryFromMToN(int count,int start)
{
using (SqlConnection = new SqlConnection(SQLHelp.Conn))
{
.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, );
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;
}
}
运行效果如下
作者陈赛
代码如下:
<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(); },
plete: function () { $("#divload").hide(); $("#more2").show(); },
suess: 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("没有更多内容加载了……");
}
}
});
}
var count = 5;
var start = 0;
init(count, start);
$(".get_more").click(function () {
start += 5;
init(count, start);
});
});
</script>
解释上面js的大体意思定义一个init方法,此方法带有两个参数count和start,count意思是每次加载显示评论数,start意思是,每次从数据库中读取的位置,比如0,5,10。
Handler.ashx处理页面的代码如下
代码如下:
页面页面的js代码如下,
<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(); },
plete: function () { $("#divload").hide(); $("#more2").show(); },
suess: 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("没有更多内容加载了……");
}
}
});
}
var count = 5;
var start = 0;
init(count, start);
$(".get_more").click(function () {
start += 5;
init(count, start);
});
});
</script></b>
解释上面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<WineNews> morenews = WineNewsManager.WineNewsQueryFromMToN(count,start);
Content = JavaScriptConvert.SerializeObject(morenews);
break;
WineNewsQueryFromMToN代码如下
代码如下:
public static IList<WineNews> WineNewsQueryFromMToN(int count,int start)
{
using (SqlConnection = new SqlConnection(SQLHelp.Conn))
{
.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, );
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;
}
}
运行效果如下
作者陈赛
上一篇:C#中HTML字符转换函数分享
下一篇:asp.net字符串处理类代码
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程