后端部分代码 一般处理程序
public void ProcessRequest(HttpContext context){context.Response.ContentType = "text/plain";string str_index = context.Request.Form.AllKeys.Contains("index") ? context.Request.Form["index"].ToString() : string.Empty;PageModel pageModel = new PageModel();pageModel.index = index;pageModel.size = size;pageModel.rowCount = rowCount;pageModel.pageCount = pageCount;List<TB_StoreInfo> list = new List<TB_StoreInfo>();string pageJson = JsonConvert.SerializeObject(pageModel);string jsonStr = JsonConvert.SerializeObject(list);//传递参数 一个list集合和一个对象context.Response.Write(string.Format("{{\"DataModel\":{0},\"PageModel\":{1}}}", jsonStr, pageJson));//传递参数 一个int类型的数据(int类型不带引号不可以的话那就给带上引号)和一个字符串类型的数据。context.Response.Write(string.Format("{{\"Index\":{0},\"Name\":\"{1}\"}}", index, "张三"));}
前端代码
<script>function GetToList(pageIndex) {$("#tbody").html("<tr><td colspan=\"12\">玩命加载中,请稍等……</td></tr>");$.ajax({url: "ajax/StoreList.ashx",data: {index: pageIndex,},cache: false,async: false,type: "POST",dataType: "Json",success: function (result) {$("#tbody").html('');for (var i = 0; i < result.DataModel.length; i++) {$("#tbody").append('<tr>');$("#tbody").append('<td>' + result.DataModel[i].StoreNo + '</td>');$("#tbody").append('<td>' + result.DataModel[i].Diqu + '</td>');$("#tbody").append('<td>' + result.DataModel[i].StoreName + '</td>');$("#tbody").append('<td>' + result.DataModel[i].RoadName + '</td>');$("#tbody").append('<td>' + result.DataModel[i].ClientType + '</td>');$("#tbody").append('<td>' + result.DataModel[i].CreateDate + '</td>');$("#tbody").append('<td>' + result.DataModel[i].Creator + '</td>');$("#tbody").append('<td>' + result.DataModel[i].ActivationDate + '</td>');$("#tbody").append('<td>' + result.DataModel[i].UseDate + '</td>');$("#tbody").append('<td>' + result.DataModel[i].DeadLine + '</td>');var total = result.DataModel[i].total;if (total <= 10 && total > 0) {$("#tbody").append("<td><p class='text-warning'>快过期:" + total + "天</p></td>");}else if (total <= 0) {$("#tbody").append("<td><p class='text-danger'>已过期</p></td>");}else {$("#tbody").append("<td><p class='text-success'>可使用:" + total + "天</p></td>");}$("#tbody").append('</tr>');}pageCount = result.PageModel.pageCount;var str = "共" + result.PageModel.rowCount + "条记录,每页" + result.PageModel.size + "条信息,共" + result.PageModel.pageCount + "页";$("#span1").html(str);$("#currentPage").html(" 第" + pageIndex + "页 ");},error: function (error) {console.log("异常" + error.responseText);$("#tbody").html('');}});}</script>