//使用Ajax异步查询数据

<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th width="30">#</th>
<th width="30"><input type="checkbox"></th>
<th>name</th>
<th width="100">操作</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td colspan="6" align="center">
<ul class="pagination"> </ul>
</td>
</tr>
</tfoot>
</table>
</div> <script type="text/javascript">
$(function () {
init();
showMenu();
}); //使用Ajax异步查询数据
function queryPage(pageno) {
var dataObj = {
"pageno": pageno, //pageno 是属性名称,是否增加双引号无所谓
"pagesize": 3
};
if (condition) {
dataObj.queryText = $("#queryText").val(); //增加模糊查询条件
}
var loadingIndex = -1;
$.ajax({
url: "${APP_PATH}/role/pageQuery.do",
type: "post",
data: dataObj,
beforeSend: function () {
loadingIndex = layer.msg('数据查询中', {icon: 6});
return true;
},
success: function (result) {
//显示结果
layer.close(loadingIndex);
if (result.success) {
var pageObj = result.page;
var roleList = pageObj.data;
var content = "";
$.each(roleList, function (i, n) {
content += "<tr>";
content += " <td>" + (i + 1) + "</td>";
content += " <td><input type='checkbox' value='" + n.id + "'></td>";
content += " <td>" + n.name + "</td>";
content += " <td>";
content += " <button type='button' onclick='window.location.href=\"${APP_PATH}/role/assign.htm?roleid=" + n.id + "\"' class='btn btn-success btn-xs'>";
content += " <i class=' glyphicon glyphicon-check'></i>";
content += " </button>";
content += " <button type='button' onclick='window.location.href=\"${APP_PATH}/role/edit.htm?pageno=" + pageObj.pageno + "&id=" + n.id + "\"' class='btn btn-primary btn-xs'>";
content += " <i class=' glyphicon glyphicon-pencil'></i>";
content += " </button>";
content += " <button type='button' class='btn btn-danger btn-xs' onclick='deleteRole(" + n.id + ",\"" + n.name + "\")'>";
content += " <i class=' glyphicon glyphicon-remove'></i>";
content += " </button>";
content += " </td>";
content += "</tr>";
//$("tbody").append(content);
$("tbody").html(content);
}); //拼接导航条
var pageContent = ""; if (pageObj.pageno != 1) {
pageContent += '<li><a href="#" onclick="changePageno(' + (pageObj.pageno - 1) + ')">上一页</a></li>';
} for (var i = 1; i <= pageObj.totalno; i++) {
if (i == pageObj.pageno) {
pageContent += '<li class="active"><a href="#" onclick="changePageno(' + i + ')">' + i + '</a></li>'; } else {
pageContent += '<li><a href="#" onclick="changePageno(' + i + ')">' + i + '</a></li>'; }
} if (pageObj.pageno != pageObj.totalno) {
pageContent += '<li><a href="#" onclick="changePageno(' + (pageObj.pageno + 1) + ')">下一页</a></li>';
} $(".pagination").html(pageContent); } else {
layer.msg("角色分页查询数据失败", {time: 1000, icon: 5, shift: 6});
}
},
error: function () {
layer.msg("角色分页查询数据错误", {time: 1000, icon: 5, shift: 6});
}
});
} var condition = false;
//条件查询
function queryRole() {
var queryText = $("#queryText"); if (queryText.val() == "") {
layer.msg("查询条件不能为空", {time: 1000, icon: 5, shift: 6}, function () {
queryText.focus();
});
return;
}
condition = true;
queryPage(1);
} function changePageno(pageno) {
//window.location.href = "<%=request.getContextPath() %>/role/index.htm?pageno="+pageno;
queryPage(pageno);
} function init() {
$(".list-group-item").click(function () {
if ($(this).find("ul")) {
$(this).toggleClass("tree-closed");
if ($(this).hasClass("tree-closed")) {
$("ul", this).hide("fast");
} else {
$("ul", this).show("fast");
}
}
}); <c:if test="${empty param.pageno}">
queryPage(1);
</c:if>
<c:if test="${not empty param.pageno}">
queryPage(${param.pageno});
</c:if>
}
</script>

最新文章

  1. mysql 数据库,表存储 大小
  2. linux定时任务生产java服务无法执行问题案例
  3. C++11的模板新特性-变长参数的模板
  4. hdu4918 Query on the subtree
  5. libev笔记
  6. UVA 1175 Ladies&#39; Choice 稳定婚姻问题
  7. 使用for循环嵌套实现乘法口诀表
  8. 斯坦福 IOS讲义 课件总结 二
  9. 介绍一个python的新的web framework——karloop框架
  10. Excel 公式(细节若干)
  11. UNIX基础--权限
  12. CentOS下查看nginx和php的编译参数
  13. input输入框自动填充黄色背景解决方案
  14. 微信小程序倒计时
  15. 算法,java代码实现打印万年历
  16. java的Calendar,获取月份少一月的问题及其它注意事项
  17. Python基础之注释,算数运算符,变量,输入和格式化输出
  18. Oracle day03 连表查询
  19. SOAP报文转成JAVA对象
  20. 我的less学习之路

热门文章

  1. javascript当中局部变量和全局变量
  2. 计算几何-poj2451-HPI
  3. jquery ajax获取后台数据后无法输出
  4. 分享链接在QQ内总是被多人举报怎么办,域名防红的方案
  5. Swiper 移动端全屏轮播图效果
  6. expect 脚本
  7. 手动搭建的react环境中,关于图片引入的问题
  8. Mac 配置cron
  9. 6_12 油田(UVa572)&lt;图的连通块DFS&gt;
  10. 台电X16pro刷机记录