$.getJSON( )的使用方法简介

$.getJSON( url [, data ] [, success(data, textStatus, jqXHR) ] )

url是必选参数,表示json数据的地址;
data是可选参数,用于请求数据时发送数据参数;
success是可参数,这是一个回调函数,用于处理请求到的数据。

   //内容页面    
   <div id="notice_div"></div>
   //分页控件
<div id="notice_pages"></div>
<script>
var roolurl = "http://" + window.location.host;
var urlAshx = roolurl + "/aa/Ashx/NoticeInfo.ashx";
//var pages = 0;
//获取分页好的公告内容
function GetNoticeList(curr, cid) {
$.getJSON(urlAshx,
{//参数
action: "notice_action",
courseid: cid,
page: curr || 1,//向服务端传的参数,此处只是演示
nums: 3//每页显示的条数
}, function (datajson) {//成功执行的方法
            if (datajson != null && typeof (datajson) == "string" && datajson.length > 0) {
              try { datajson = JSON.parse(datajson); } catch (e) { datajson = eval("(" + datajson + ")"); } } var norice_content = "";
//alert(datajson.pages);
$(datajson.rows).each(function (n, Row) {
norice_content += " <div class='panel panel-default'>";
norice_content += " <div class='panel-heading'>";
norice_content += " <h3 class='panel-title'>";
norice_content += Row.CreateDate;
norice_content += "           ";
norice_content += Row.Creater;
norice_content += " </h3>";
norice_content += " </div>";
norice_content += " <div class='panel-body'>";
norice_content += Row.NoticeContent;
norice_content += " </div>";
norice_content += " </div>";
});
$('#notice_div').html(norice_content); //alert(11);
//调用分页
laypage({
cont: 'notice_pages',//容器。值支持id名、原生dom对象,jquery对象。【如该容器为】:<div id="page1"></div>
pages: datajson.pages,//总页数
groups: 5, //连续显示分页数
skip: false, //是否开启跳页
skin: '#AF0000',
curr: curr || 1, //当前页,
jump: function (obj, first) {//触发分页后的回调
if (!first) {//点击跳页触发函数自身,并传递当前页:obj.curr
GetNoticeList(obj.curr, cid);
}
}
});
});
}
$(document).ready(function () {
GetNoticeList(0, '<%=_courseid%>')
});
</script>

后台数据反馈

private string GetNewsByPage(HttpContext context)
{
#region //分页 算法
int page = 0;
int.TryParse(context.Request.Params["page"], out page);//当前第几页
int nums = 0;
int.TryParse(context.Request.Params["nums"], out nums);//每页显示几条数据
int StartIndex = (page - 1) * nums + 1;
int EndIndex = page * nums;
#endregion //StringBuilder strWhere = new StringBuilder();
#region // 拼Sql Where 条件 #endregion int total = 0;
DataTable dt = bll_News.GetListByPage("", "postdate", StartIndex, EndIndex);
total = bll_News.GetRecordCount("");
string strjosn = AppCode.DataTableConvertJson.DataTableToJson(dt);
int pages = Convert.ToInt32(Math.Ceiling((double)total / (double)nums)); // 页数
return "{\"total\":" + total + ",\"pages\":" + pages + ",\"rows\":" + strjosn + "}";
}

最新文章

  1. ThinkPHP3.2 G函数代码及 使用方法
  2. windows下使用mysql双机热备功能
  3. noip模拟赛(10.4) 字典序(dictionary)
  4. ortp库入门
  5. GEOS库学习之三:空间关系、DE-9IM和谓词
  6. jsoup抓取借书记录
  7. OSChina中远程GIT仓库同步探索
  8. 媒体查询的应用以及在css3中的变革
  9. mysql定时器三部曲
  10. ie67 设置最小宽度最小高度
  11. [其他]volatile 关键字
  12. [SQLite]SQL语法
  13. day8、 显示Linux路由表、各列信息
  14. IEEE1588协议简介
  15. u-boot核心初始化
  16. Reactor 3 学习笔记(1)
  17. TFDStoredProc执行sql server的部分存储过程报错,有的是好的。
  18. css3实现切片动画
  19. ExtJs对js基本语法扩展支持
  20. python开发_tkinter_自己做的猜数字小程序

热门文章

  1. 常用[js,css,jquery,html]
  2. Alljoyn瘦客户端库介绍(官方文档翻译 下)
  3. 在VMWare中建立Hadoop虚拟集群的详细步骤(使用CentOS)
  4. AngularJS2 + ASP.NET MVC项目
  5. 【Android环境搭建】解决安装使用SDK Manager更新时的问题
  6. promise实现原理
  7. 《FaceBook效应》——读后总结
  8. iOS----- Crash 分析(文二)-崩溃日志组成
  9. C#设计模式系列:桥接模式(Bridge)
  10. 从零学java--传智播客