ホームページ  >  記事  >  ウェブフロントエンド  >  Jquery Ajax.ashx の効率的なページング実装 code_jquery

Jquery Ajax.ashx の効率的なページング実装 code_jquery

WBOY
WBOYオリジナル
2016-05-16 18:44:071379ブラウズ

以前は、UpdatePanel UpdateProgress やその他のコントロールを乱用することに慣れていましたが、更新を行わないことを追求し、この読み込み画面のプロンプトを表示するようにしていましたが、パフォーマンスが低下しているように感じられることがありました。ウェブサイトの完全性が損なわれました。

しかし、Jquery を学習した後、Jquery.ajax、Jquery.get、その他のメソッドについて学び、Web サービスと .ashx ファイルを使用してサーバーと対話する方法を学びました。
今回は、Jquery ページングが .ashx ファイルと連携します。
3 つの .ashx (PreviewHandler.ashx、PageHandler.ashx、NextHandler.ashx) を作成し、それぞれ現在のページ、次のページ、前のページを処理します。
PageHandler.ashx

コードをコピー コードは次のとおりです:

public void ProcessRequest (HttpContext context )
{
context.Response.ContentType = "text/plain";
IQueryableanswer = xt.Answer.Take(10);
StringBuilder sb = new StringBuilder( );
sb.Append("");
foreach (答えはa)
{
sb.Append("");
}
sb.Append("
回答内容回答ユーザー名作成時刻
" a.Answer_content "" a.Answer_UserName "" a.Answer_Creatime "
");
context.Response.Write(sb);
}

NextHandler.ashx
コードをコピー コードは次のとおりです:

public void ProcessRequest( HttpContext context)
{
context.Response.ContentType = "text/plain";
int RowCount = 10
int Current = Convert.ToInt32(context.Request.Params[" Index"] ) 1;
IQueryableanswer = xt.Answer.Skip(RowCount * (Current - 1)).Take(RowCount);
StringBuilder sb = new StringBuilder();
sb .Append( "");
foreach (答えは a)
{
sb.Append("");
}
sb.Append ( "
回答内容回答ユーザー名作成time
" a.Answer_content "< ; /td>" a.Answer_UserName "" a.Answer_Creatime "
");
context.Response.Write(sb)
}

PreviewHandler.ashx
コードをコピーします コードは次のとおりです:

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = " text/plain" ;
int RowCount = 10;
int Current = Convert.ToInt32(context.Request.Params["index"]) - 1;
IQueryable 回答 = xt.Answer. Skip(RowCount * (現在 - 1)).Take(RowCount);
StringBuilder sb = new StringBuilder()
sb.Append("回答内容");
foreach (回答a回答)
{
sb.Append("");
}
sb.Append("
回答ユーザー名作成時刻
" a.Answer_content "" a.Answer_UserName "
");
context.Response.Write(sb) ;
}

3 つのファイルのコードはほとんど似ており、Jquery.get()
<🎜 を使用して HTML または aspx ファイルを通じて呼び出されます。 >コードをコピー コードは次のとおりです:







上一页
下一页




var Init=function(){
$.get("PageHandler.ashx",function(data){
document.getElementById('content').innerHTML=data;
$(' .currIndex').attr('value',"1");
document.getElementById("PageInfo").innerHTML="当前第1页"
});
}
var Preview=function(){
var current=$('.currIndex').attr('value');
var pre=数値(現在)-1;
$.get("PreviewHandler.ashx",{index:current},function(data){
document.getElementById('content').innerHTML=data;
$('.currIndex') .attr('value',pre);
document.getElementById("PageInfo").innerHTML="当前第" pre "页">});
}
var Next=function(){
var current=$('.currIndex').attr('value');
var next=数値(現在) 1;
$.get("NextHandler.ashx",{index:current},function(data){
document.getElementById('content').innerHTML=data;
$('.currIndex') .attr('value',next);
document.getElementById("PageInfo").innerHTML="当前第" next "页">});
}


は、.ashx ファイルで生成されたデータをすぐに、NextHandler.ashx ファイルの内容で PageHandler.ashx ファイルの内容を覆います。 🎜>
解決を待っている問題があります、これらの行程を実行します、我在.ashx文件追加 1 つ
さらに、.aspx 文件にも del メソッドが記述されていますが、会議エラー、オブジェクト予期エラー、この警告、このエラーは del メソッドに到達できません、他の生成時間、不達、未解決、
谁能解決可能告我。。。
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。