使用$.ajax()方法处理json数据格式,后台传过来的json格式,通过jquery中的$.ajax()之后没有结果。传过来的json格式是这样的
{"infos":[{"id":402881e9564b22f701564b251aef0001,"title":"火影","publishingTime":"2016-08-02 20:05:38.0","isEditable":"true"},{"id":402881e9565a7f3601565a86f0c30001,"title":"龙珠","publishingTime":"2016-08-05 19:46:48.0","isEditable":"true"},{"id":402881e9565a7f3601565a8720ac0002,"title":"哈哈","publishingTime":"2016-08-05 19:47:00.0","isEditable":"true"},{"id":402881e9565a7f3601565a87464b0003,"title":"海贼","publishingTime":"2016-08-05 19:47:10.0","isEditable":"true"},{"id":402881e9565a7f3601565a87b47c0004,"title":"海贼王","publishingTime":"2016-08-05 19:47:38.0","isEditable":"true"}],"pageBean":{"pageSize":5,"currentPage":1,"totalPage":1,"hasPrevious":false,"HasNext":false}}
那个jquery的$.ajax()是这样写的
$(function () {
$.post("getFirstInfoList.action", null, function (data) {
var totalPage = data.totalPage;
PageClick(1, totalPage, 3);
});
PageClick = function (page, totalPage, spanInterval) {
$.ajax({
url: "getFirstInfoList.action",
data: { "page": page },
type: "post",
dataType: "json",
success: function (data) {
//索引从1开始
//将当前页索引转为int类型
var intPageIndex = parseInt(page);
//获取显示数据的表格
var table = $("#content");
//清楚表格中内容
$("#content tr").remove();
var infos=data.infos;
//向表格中添加内容
for (var i = 0; i < infos.length; i++) {
table.append(
$("<tr><td>" +
infos[i].id
+ "</td><td>" +
infos[i].title
+ "</td><td>" +
infos[i].publishingTime
+ "</td><td>" +
infos[i].isEditable
+ "</td></tr>")
);
} //for
//创建分页
//将总记录数结果 得到 总页码数
var pageS = data.totalPage;
var $pager = $("#pager");
//清楚分页div中的内容
$("#pager span").remove();
$("#pager a").remove();
//添加第一页
if (intPageIndex == 1)
$pager.append("<span class='disabled'>第一页</span>");
else {
var first = $("<a href='javascript:void(0)' first='" + 1 + "'>第一页</a>").click(function () {
PageClick($(this).attr('first'), totalPage, spanInterval);
return false;
});
$pager.append(first);
}
//添加上一页
if (intPageIndex == 1)
$pager.append("<span class='disabled'>上一页</span>");
else {
var pre = $("<a href='javascript:void(0)' pre='" + (intPageIndex - 1) + "'>上一页</a>").click(function () {
PageClick($(this).attr('pre'), totalPage, spanInterval);
return false;
});
$pager.append(pre);
}
//设置分页的格式 这里可以根据需求完成自己想要的结果
var interval = parseInt(spanInterval); //设置间隔
var start = Math.max(1, intPageIndex - interval); //设置起始页
var end = Math.min(intPageIndex + interval, pageS)//设置末页
if (intPageIndex < interval + 1) {
end = (2 * interval + 1) > pageS ? pageS : (2 * interval + 1);
}
if ((intPageIndex + interval) > pageS) {
start = (pageS - 2 * interval) < 1 ? 1 : (pageS - 2 * interval);
}
//生成页码
for (var j = start; j < end + 1; j++) {
if (j == intPageIndex) {
var spanSelectd = $("<span class='current'>" + j + "</span>");
$pager.append(spanSelectd);
} //if
else {
var a = $("<a href='javascript:void(0)'>" + j + "</a>").click(function () {
PageClick($(this).text(), totalPage, spanInterval);
return false;
});
$pager.append(a);
} //else
} //for
//上一页
if (intPageIndex == totalPage) {
$pager.append("<span class='disabled'>下一页</span>");
}
else {
var next = $("<a href='javascript:void(0)' next='" + (intPageIndex + 1) + "'>下一页</a>").click(function () {
PageClick($(this).attr("next"), totalPage, spanInterval);
return false;
});
$pager.append(next);
}
//最后一页
if (intPageIndex == pageS) {
$pager.append("<span class='disabled'>最后一页</span>");
}
else {
var last = $("<a href='javascript:void(0)' last='" + pageS + "'>最后一页</a>").click(function () {
PageClick($(this).attr("last"), totalPage, spanInterval);
return false;
});
$pager.append(last);
}
} //sucess
}); //ajax
}; //function
}); //ready
为啥经过这个jquery之后就没数据了
我有一双明亮的眼睛
我有一双明亮的眼睛
相关分类