国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

利用 Linq+Jquery+Ajax 實(shí)現(xiàn)異步分頁功能可簡化帶寬壓力

來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:52:09
文檔

利用 Linq+Jquery+Ajax 實(shí)現(xiàn)異步分頁功能可簡化帶寬壓力

利用 Linq+Jquery+Ajax 實(shí)現(xiàn)異步分頁功能可簡化帶寬壓力:在Web顯示的時(shí)候我們經(jīng)常會(huì)遇到分頁顯示,而網(wǎng)上的分頁方法甚多,但都太過于消耗帶寬,所以我想到了用Ajax來分頁,利用返回的Json來處理返回的數(shù)據(jù),大大簡化了帶寬的壓力。先說下思路,無非就是異步執(zhí)行ajax 把新列表所需要的數(shù)據(jù)用json格式返回來,輸出ta
推薦度:
導(dǎo)讀利用 Linq+Jquery+Ajax 實(shí)現(xiàn)異步分頁功能可簡化帶寬壓力:在Web顯示的時(shí)候我們經(jīng)常會(huì)遇到分頁顯示,而網(wǎng)上的分頁方法甚多,但都太過于消耗帶寬,所以我想到了用Ajax來分頁,利用返回的Json來處理返回的數(shù)據(jù),大大簡化了帶寬的壓力。先說下思路,無非就是異步執(zhí)行ajax 把新列表所需要的數(shù)據(jù)用json格式返回來,輸出ta

在Web顯示的時(shí)候我們經(jīng)常會(huì)遇到分頁顯示,而網(wǎng)上的分頁方法甚多,但都太過于消耗帶寬,所以我想到了用Ajax來分頁,利用返回的Json來處理返回的數(shù)據(jù),大大簡化了帶寬的壓力。先說下思路,無非就是異步執(zhí)行ajax 把新列表所需要的數(shù)據(jù)用json格式返回來,輸出table,你可以輸出ui li(輸出效率高) 在頁面上。

效果圖:
 
Html代碼:
代碼如下:


設(shè)置它們的Class = "page" 以便于給它們增加Click事件操作分頁
<div id="showPage" style="width: 650px; margin: 0 auto; display: none" class="pages">
<div style="float: left">
<a id="first" class="pages">首頁</a>
<a id="prev" class="pages">上頁</a>
<a id="next" class="pages">下頁</a>
<a id="last" class="pages">尾頁</a>
跳轉(zhuǎn)到第<input type="text" id="txtGoPage" style="width: 45px; height: 15px; border: 1px solid" />

</div>
<div style="margin: 0; float: left">
<input type="button" class="pages btn btn-info" id="go" value="跳轉(zhuǎn)" />
共<span id="SumCount"></span> 條數(shù)據(jù),每頁<span id="ItemCount"></span> 條,
當(dāng)前<span id="Index"></span>/<span id="PageCount"></span>頁
</div>
</div>
用下面的div
輸出返回的結(jié)果
<div id="divBadProductInfo"></div>

Css代碼:
代碼如下:

/*分頁*/
.pages {
cursor: pointer;
text-align: center;
margin: 0 auto;
padding-right: 0px;
padding-bottom: 2px;
padding-top: 2px;
font-family: verdana, helvetica, arial, sans-serif;
}

.pages a {
border-right: 1px solid;
padding-right: 6px;
border-top: 1px solid;
padding-left: 6px;
padding-bottom: 0px;
overflow: hidden;
border-left: 1px solid;
line-height: 20px;
margin-right: 2px;
padding-top: 0px;
border-bottom: 1px solid;
height: 30px;
}

.pages a {
border-left-color: #e6e7e1;
border-bottom-color: #e6e7e1;
color: #09c;
border-top-color: #e6e7e1;
background-color: #fff;
border-right-color: #e6e7e1;
}

.pages a:hover {
text-decoration: none;
border-left-color: #09c;
border-bottom-color: #09c;
border-top-color: #09c;
border-right-color: #09c;
}

.pages a.next {
border-left-color: #09c;
border-bottom-color: #09c;
border-top-color: #09c;
border-right-color: #09c;
}

JS代碼:

引入: <script src="assets/js/jquery-1.8.2.min.js"></script>//可以為其他版本
代碼如下:


$(document).ready(function ()
{
//檢索條件
var search = $("#txtFactroy").val() + "_" + $("#txtTimeSelect").val()
+ "_" + $("#txtPinfan").val() + "_" +
$('input[type="checkbox"][name="option1"]:checked').val();
$.ajax({
type: "post",<span style="color:#ff0000;">//回傳格式
url: "ResponseHandler.ashx"http://回傳到一般處理程序中處理//回傳參數(shù)表示請求的是第幾頁,encodeURIComponent 格式化中文以防亂碼
data: "BadProductWhere=" + encodeURIComponent(search) + "&currPage=1",
datatype: "json",//把返回來的數(shù)據(jù) json
async: false,//禁止使用瀏覽器緩存
success: function (returnData, textstatus, xmlhttprequest)
{
$("#showPage").css('display', 'block');//顯示分頁
$("#divBadProductInfo").html(returnData.split('_')[0]);//返回值分割顯示
var page = returnData.split('_')[1].split(',');
$("#SumCount").text(page[0]);//共多少條數(shù)據(jù)
$("#ItemCount").text(page[1]);//每頁多少條數(shù)據(jù)
$("#Index").text(page[2]);//當(dāng)前頁
$("#PageCount").text(page[3]);//共多少頁 }
});
//清除轉(zhuǎn)向頁面
$("#txtGoPage").val("");

//分頁操作動(dòng)作
$(".pages").click(function () {
//總頁數(shù)大于1的情況下上下首末頁可用
if (parseFloat($("#PageCount").html()) > 1) {
//取得控件類型是ID還是class
var type = $(this).attr("id");
//取得當(dāng)前是多少頁
var thisindex = $("#Index").text();
var search = $("#txtFactroy").val() + "_" + $("#txtTimeSelect").val()
+ "_" + $("#txtPinfan").val() + "_" +
$('input[type="checkbox"][name="option1"]:checked').val();
switch (type) {
case 'first':
{
$("#txtGoPage").val("");
badpageindex = 1;
BadPageIndex(1, search);//Ajax 回傳函數(shù)
return;
}
case 'prev':
{
$("#txtGoPage").val("");
badpageindex = parseInt(thisindex) - 1;
if (badpageindex < 1) return;
BadPageIndex(badpageindex, search);
return;
}
case 'next':
{
$("#txtGoPage").val("");
badpageindex = parseInt(thisindex) + 1;
if (badpageindex > parseInt($("#PageCount").html())) return;
else
BadPageIndex(badpageindex, search);
return;
}
case 'last':
{
var max = parseInt($("#PageCount").html());
$("#txtGoPage").val("");
badpageindex = max;
BadPageIndex(max, search);
return;
}
case 'go':
{
var _go = $("#txtGoPage").val();
badpageindex = _go;
BadPageIndex(_go, search);
return;
}
}
}
})
});

代碼如下:


var badpageindex;
//index,頁面索引例如1,2,3
//BadProductWhere 查詢條件
function BadPageIndex(index, searchwhere) {
$.ajax({
type: "post",
url: "ResponseHandler.ashx",
data: "BadProductWhere=" + encodeURIComponent(searchwhere) + "&currPage=" + index,
datatype: "json",
async: false,
success: function (returnData, textstatus, xmlhttprequest) {
$("#divDisplay").css('display', 'none');
$("#showPage").css('display', 'block');
$("#divBadProductInfo").html(returnData.split('_')[0]);
var page = returnData.split('_')[1].split(',');
$("#SumCount").text(page[0]);
$("#ItemCount").text(page[1]);
$("#Index").text(page[2]);
$("#PageCount").text(page[3]);
},
error: function () {
alert("服務(wù)錯(cuò)誤");
}
});

}

C# 代碼:(ResponseHandler.ashx)
代碼如下:


/// <summary>
/// 每頁顯示條數(shù)
/// </summary>
private int pageSize = 20;
StringBuilder sbBadProductInfo = new StringBuilder();
if (!string.IsNullOrEmpty(context.Request["BadProductWhere"]) &&
!string.IsNullOrEmpty(context.Request["currPage"]))
{
#region // B品標(biāo)題信息
sbBadProductInfo.Append(@"<div class='row-fluid'>
<div class='span12 widget'><div class='widget-header'>
<span class='title'>
<i class='icol-blog'></i>B品箱單信息
</span>
</div>");
sbBadProductInfo.Append(@"<div class='widget-content summary-list'>
<div class='row-fluid' style='padding-top: 2px;'>
<div class='span12 section'>
<table class='table table-bordered table-striped'>
<thead>
<tr>
<th>箱單編號(hào)</th>
<th>裝箱生成日期</th>
<th>工廠名稱</th>
<th>裝箱品番</th>
<th>裝箱箱號(hào)</th>
<th>裝箱件數(shù)</th>
<th>倉庫確認(rèn)</th>
<th>出庫確認(rèn)人</th>
<th>出庫日期</th>
<th>查看明細(xì)</th>
</tr>
</thead><tbody>");
#endregion
List<bstate_view> lstGetBadProductData = (from p in lstGetBadProductData
where !string.IsNullOrEmpty(p.出庫確認(rèn)人) && p.出庫日期 != null
select p).ToList<bstate_view>();
string pageInfo = lstGetBadProductData.Count() + "," + pageSize + "," + context.Request["currPage"] +
"," + (lstGetBadProductData.Count() % 20 == 0 ? (lstGetBadProductData.Count() / 20) :
(lstGetBadProductData.Count() / 20 + 1));
List<bstate_view> lstGetBadItemData = (lstGetBadProductData.Count > pageSize ?
lstGetBadProductData.Skip(int.Parse(context.Request["currPage"]) == 1 ? 0 :
pageSize * (int.Parse(context.Request["currPage"]) - 1)).Take(pageSize)
: lstGetBadProductData).ToList<bstate_view>();
#region ==>B品箱單信息
foreach (var item in lstGetBadItemData)
{
var cssName = rowCount % 2 == 0 ? "warning" : "error";
sbBadProductInfo.Append(@"<tr class='" + cssName + "'>");
sbBadProductInfo.Append(@"<td>" + item.箱單編號(hào) + "</td>");
sbBadProductInfo.Append(@"<td>" + item.裝箱生成日期 + "</td>");
sbBadProductInfo.Append(@"<td>" + item.工廠名稱 + "</td>");
sbBadProductInfo.Append(@"<td>" + item.裝箱品番 + "</td>");
sbBadProductInfo.Append(@"<td>" + item.裝箱箱號(hào) + "</td>");
sbBadProductInfo.Append(@"<td>" + item.裝箱件數(shù) + "</td>");
sbBadProductInfo.Append(@"<td>" + item.倉庫確認(rèn) + "</td>");
sbBadProductInfo.Append(@"<td>" + item.出庫確認(rèn)人 + "</td>");
sbBadProductInfo.Append(@"<td>" + item.出庫日期 + "</td>");
sbBadProductInfo.Append(@"<td><input type='button' class='btn btn-primary'
style='width: 80px; height: 30px;' value='查看明細(xì)'");
sbBadProductInfo.Append(@" onclick='OpenBadInfo(" + item.箱編號(hào) + ");'/></td></tr>");
rowCount++;
}
sbBadProductInfo.Append(@"</tbody></table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>");
#endregion

context.Response.Write(sbBadProductInfo.ToString() + "_" + pageInfo);
context.Response.End();

分頁效果:


聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

利用 Linq+Jquery+Ajax 實(shí)現(xiàn)異步分頁功能可簡化帶寬壓力

利用 Linq+Jquery+Ajax 實(shí)現(xiàn)異步分頁功能可簡化帶寬壓力:在Web顯示的時(shí)候我們經(jīng)常會(huì)遇到分頁顯示,而網(wǎng)上的分頁方法甚多,但都太過于消耗帶寬,所以我想到了用Ajax來分頁,利用返回的Json來處理返回的數(shù)據(jù),大大簡化了帶寬的壓力。先說下思路,無非就是異步執(zhí)行ajax 把新列表所需要的數(shù)據(jù)用json格式返回來,輸出ta
推薦度:
標(biāo)簽: 利用 分頁 帶寬
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 在线视频欧美日韩 | 欧美视频精品一区二区三区 | 91久久精品一区二区三区 | 久久亚洲一区二区 | 美国一级大黄大色毛片 | 中文字幕久久亚洲一区 | 国产视频在 | 国产精品视频专区 | 亚洲国产精品免费 | 青青热久久国产久精品 | 精品国产a | 中日韩在线| 欧美 亚洲 校园 第一页 | 久久一区二区三区四区 | 日本高清在线播放一区二区三区 | 精品视频在线观看视频免费视频 | 日本久久网站 | 国产未成女年一区二区 | 成人看的一级毛片 | 亚洲视频在线观看 | 日韩免费网站 | 亚洲综合国产 | 精品视频一区二区三区四区五区 | 亚洲欧美精选 | 日韩电影免费在线观看网址 | 在线观看国产欧美 | 日本特级淫片免费看 | 色综合色狠狠天天综合色 | 自拍偷自拍亚洲精品情侣 | 国产黄色在线看 | 最新欧美日韩 | 欧美日韩视频一区二区 | 国产a久久精品一区二区三区 | 国产成人99久久亚洲综合精品 | 欧美一级高清片欧美国产欧美 | 国产日韩高清一区二区三区 | 欧美日本三级 | 亚洲一区二区精品 | 亚洲国产视频网 | 成人午夜精品久久久久久久小说 | 欧美一区二区日韩一区二区 |